Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
|
|
@ -10,7 +10,6 @@ V NOT_VISITED = 1
|
|||
|
||||
T PercolatedException
|
||||
(Int, Int) t
|
||||
|
||||
F (t)
|
||||
.t = t
|
||||
|
||||
|
|
@ -24,7 +23,7 @@ F pgrid(cell, percolated)
|
|||
V where = percolated[0]
|
||||
print(‘!) ’(‘ ’ * where)‘’:cell2char[cell[:nn - 1][where]])
|
||||
|
||||
F walk_maze(m, n, &cell, indx) X(PercolatedException) -> N
|
||||
F walk_maze(m, n, &cell, indx) X(PercolatedException) -> Void
|
||||
cell[n][m] = indx
|
||||
I n < :nn - 1 & cell[n + 1][m] == :NOT_VISITED
|
||||
walk_maze(m, n + 1, &cell, indx)
|
||||
|
|
|
|||
|
|
@ -2,28 +2,28 @@
|
|||
#define EMPTY " "
|
||||
#define WET "v"
|
||||
|
||||
Dim Shared As String grid()
|
||||
Dim Shared As String grid
|
||||
Dim Shared As Integer last, lastrow, m, n
|
||||
|
||||
Sub make_grid(x As Integer, y As Integer, p As Double)
|
||||
m = x
|
||||
n = y
|
||||
Redim Preserve grid(x*(y+1)+1)
|
||||
last = Len(grid)
|
||||
Dim As Integer lastrow = last-n
|
||||
Sub makeGrid(x As Integer, y As Integer, p As Double)
|
||||
Dim As Integer i, j
|
||||
|
||||
m = x
|
||||
n = y
|
||||
grid = String(x*(y+1)+1, Chr(10))
|
||||
last = Len(grid)
|
||||
lastrow = last - n
|
||||
For i = 0 To x-1
|
||||
For j = 1 To y
|
||||
grid(1+i*(y+1)+j) = Iif(Rnd < p, EMPTY, SOLID)
|
||||
Mid(grid, 1+i*(y+1)+j, 1) = Iif(Rnd < p, EMPTY, SOLID)
|
||||
Next j
|
||||
Next i
|
||||
End Sub
|
||||
|
||||
Function ff(i As Integer) As Boolean
|
||||
If i <= 0 Or i >= last Or grid(i) <> EMPTY Then Return 0
|
||||
grid(i) = WET
|
||||
Return i >= lastrow Or (ff(i+m+1) Or ff(i+1) Or ff(i-1) Or ff(i-m-1))
|
||||
Function ff(i As Integer) As Integer
|
||||
If i <= 0 Or i >= last Or Mid(grid, i, 1) <> EMPTY Then Return 0
|
||||
Mid(grid, i, 1) = WET
|
||||
Return (i >= lastrow) Or ff(i+m+1) Or ff(i+1) Or ff(i-1) Or ff(i-m-1)
|
||||
End Function
|
||||
|
||||
Function percolate() As Integer
|
||||
|
|
@ -33,24 +33,23 @@ Function percolate() As Integer
|
|||
Return 0
|
||||
End Function
|
||||
|
||||
Randomize Timer
|
||||
makeGrid(15, 15, 0.55)
|
||||
percolate()
|
||||
Print "15x15 grid:";
|
||||
Print grid
|
||||
|
||||
Print "running 10,000 tests for each case:"
|
||||
Dim As Double p
|
||||
Dim As Integer ip, i, cont
|
||||
|
||||
make_grid(15, 15, 0.55)
|
||||
Print "15x15 grid:"
|
||||
For i = 1 To Ubound(grid)
|
||||
Print grid(i);
|
||||
If i Mod 15 = 0 Then Print
|
||||
Next i
|
||||
|
||||
Print !"\nrunning 10,000 tests for each case:"
|
||||
For ip As Ubyte = 0 To 10
|
||||
Dim As Integer ip, i, cnt
|
||||
For ip = 0 To 10
|
||||
p = ip / 10
|
||||
cont = 0
|
||||
cnt = 0
|
||||
For i = 1 To 10000
|
||||
make_grid(15, 15, p)
|
||||
cont += percolate()
|
||||
makeGrid(15, 15, p)
|
||||
cnt += (percolate() = 1)
|
||||
Next i
|
||||
Print Using "p=#.#: #.####"; p; cont/10000
|
||||
Print Using "p=#.#: #.####"; p; Abs(cnt / 10000)
|
||||
Next ip
|
||||
|
||||
Sleep
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue