Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
|
|
@ -0,0 +1,64 @@
|
|||
brd$ = "
|
||||
.##.##.
|
||||
#######
|
||||
#######
|
||||
.#####.
|
||||
..###..
|
||||
...#...
|
||||
"
|
||||
moves[][] = [ [ -3 0 ] [ 0 3 ] [ 3 0 ] [ 0 -3 ] [ 2 2 ] [ 2 -2 ] [ -2 2 ] [ -2 -2 ] ]
|
||||
global brd[][] maxr maxc maxcnt .
|
||||
func solve r c cnt .
|
||||
if cnt > maxcnt
|
||||
return 1
|
||||
.
|
||||
for m = 1 to len moves[][]
|
||||
rn = r + moves[m][1]
|
||||
cn = c + moves[m][2]
|
||||
if rn >= 1 and rn <= maxr and cn >= 1 and cn <= maxc and brd[rn][cn] = 0
|
||||
brd[rn][cn] = cnt
|
||||
if solve rn cn (cnt + 1) = 1
|
||||
return 1
|
||||
.
|
||||
brd[rn][cn] = 0
|
||||
.
|
||||
.
|
||||
return 0
|
||||
.
|
||||
proc prepare . r0 c0 .
|
||||
brd$[] = strsplit brd$ "\n"
|
||||
maxc = len brd$[2]
|
||||
maxr = len brd$[] - 2
|
||||
len brd[][] maxr
|
||||
for r to maxr
|
||||
for c to maxc
|
||||
h = if substr brd$[r + 1] c 1 = "#"
|
||||
maxcnt += h
|
||||
brd[r][] &= h - 1
|
||||
if h = 1 and r0 = 0
|
||||
r0 = r
|
||||
c0 = c
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
proc printbrd . .
|
||||
numfmt 0 3
|
||||
for r to maxr
|
||||
for c to maxc
|
||||
if brd[r][c] = -1
|
||||
write " "
|
||||
else
|
||||
write brd[r][c]
|
||||
.
|
||||
.
|
||||
print ""
|
||||
.
|
||||
.
|
||||
prepare r0 c0
|
||||
brd[r0][c0] = 1
|
||||
if solve r0 c0 2 = 1
|
||||
printbrd
|
||||
else
|
||||
print "no solutions found"
|
||||
.
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
Dim Shared As Integer neighbours(7, 1) => {{2, 2}, {-2, 2}, {2, -2}, {-2, -2}, {3, 0}, {0, 3}, {-3, 0}, {0, -3}}
|
||||
Dim Shared As Integer cnt
|
||||
Dim Shared As Integer pWid
|
||||
Dim Shared As Integer pHei
|
||||
Dim Shared As Integer pa()
|
||||
|
||||
Function isValid(a As Integer, b As Integer) As Integer
|
||||
Return (-1 < a And a < pWid And -1 < b And b < pHei)
|
||||
End Function
|
||||
|
||||
Function iterate(pa() As Integer, x As Integer, y As Integer, v As Integer) As Integer
|
||||
If v > cnt Then Return 1
|
||||
Dim As Integer i, a, b, r
|
||||
For i = Lbound(neighbours, 1) To Ubound(neighbours, 1)
|
||||
a = x + neighbours(i, 0)
|
||||
b = y + neighbours(i, 1)
|
||||
If isValid(a, b) And pa(a, b) = 0 Then
|
||||
pa(a, b) = v
|
||||
r = iterate(pa(), a, b, v + 1)
|
||||
If r = 1 Then Return r
|
||||
pa(a, b) = 0
|
||||
End If
|
||||
Next i
|
||||
Return 0
|
||||
End Function
|
||||
|
||||
Function solve(pz As String, w As Integer, h As Integer) As Boolean
|
||||
Redim pa(w - 1, h - 1) As Integer
|
||||
|
||||
Dim As Integer f, y, x
|
||||
pWid = w
|
||||
pHei = h
|
||||
For y = 0 To h - 1
|
||||
For x = 0 To w - 1
|
||||
If Mid(pz, f + 1, 1) = "1" Then
|
||||
pa(x, y) = 0
|
||||
cnt += 1
|
||||
Else
|
||||
pa(x, y) = -1
|
||||
End If
|
||||
f += 1
|
||||
Next x
|
||||
Next y
|
||||
|
||||
For y = 0 To h - 1
|
||||
For x = 0 To w - 1
|
||||
If pa(x, y) = 0 Then
|
||||
pa(x, y) = 1
|
||||
If iterate(pa(), x, y, 2) = 1 Then Return True
|
||||
pa(x, y) = 0
|
||||
End If
|
||||
Next x
|
||||
Next y
|
||||
Return False
|
||||
End Function
|
||||
|
||||
Sub printSolution(w As Integer, h As Integer)
|
||||
Dim As Integer i, j
|
||||
|
||||
For j = 0 To h - 1
|
||||
For i = 0 To w - 1
|
||||
If pa(i, j) = -1 Then
|
||||
Print " ";
|
||||
Else
|
||||
Print Using " ##"; pa(i, j);
|
||||
End If
|
||||
Next i
|
||||
Print
|
||||
Next j
|
||||
End Sub
|
||||
|
||||
Dim As Integer r
|
||||
r = solve("011011011111111111111011111000111000001000", 7, 6)
|
||||
If r Then
|
||||
printSolution(7, 6)
|
||||
Else
|
||||
Print "No solution!"
|
||||
End If
|
||||
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue