A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
|
|
@ -0,0 +1,15 @@
|
|||
MazeGraphics[m_, n_] :=
|
||||
Block[{$RecursionLimit = Infinity,
|
||||
unvisited = Tuples[Range /@ {m, n}], maze},
|
||||
maze = Graphics[{Line[{{#, # - {0, 1}}, {#, # - {1, 0}}}] & /@
|
||||
unvisited,
|
||||
Line[{{0, n}, {0, 0}, {m, 0}}]}]; {unvisited =
|
||||
DeleteCases[unvisited, #];
|
||||
Do[If[MemberQ[unvisited, neighbor],
|
||||
maze = DeleteCases[
|
||||
maze, {#,
|
||||
neighbor - {1, 1}} | {neighbor, # - {1, 1}}, {5}]; #0@
|
||||
neighbor], {neighbor,
|
||||
RandomSample@{# + {0, 1}, # - {0, 1}, # + {1, 0}, # - {1,
|
||||
0}}}]} &@RandomChoice@unvisited; maze];
|
||||
maze = MazeGraphics[21, 13]
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
MazeGraph[m_, n_] :=
|
||||
Block[{$RecursionLimit = Infinity, grid = GridGraph[{m, n}],
|
||||
visited = {}},
|
||||
Graph[Range[m n], Reap[{AppendTo[visited, #];
|
||||
Do[
|
||||
If[FreeQ[visited, neighbor],
|
||||
Sow[# <-> neighbor]; #0@neighbor], {neighbor,
|
||||
RandomSample@AdjacencyList[grid, #]}]} &@
|
||||
RandomChoice@VertexList@grid][[2, 1]],
|
||||
GraphLayout -> {"GridEmbedding", "Dimension" -> {m, n}}]];
|
||||
maze = MazeGraph[13, 21]
|
||||
Loading…
Add table
Add a link
Reference in a new issue