Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Maze-generation/Mathematica/maze-generation-1.math
Normal file
15
Task/Maze-generation/Mathematica/maze-generation-1.math
Normal file
|
|
@ -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]
|
||||
11
Task/Maze-generation/Mathematica/maze-generation-2.math
Normal file
11
Task/Maze-generation/Mathematica/maze-generation-2.math
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
MazeGraph[m_, n_] :=
|
||||
Block[{$RecursionLimit = Infinity, grid = GridGraph[{m, n}],
|
||||
unvisitedQ}, unvisitedQ[_] := True;
|
||||
Graph[Range[m n], Reap[{unvisitedQ[#] = False;
|
||||
Do[
|
||||
If[unvisitedQ[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