Maze solving: Difference between revisions
Content added Content deleted
(Added Uiua solution) |
|||
Line 5,803: | Line 5,803: | ||
| > > > ^ | | > |
| > > > ^ | | > |
||
+---+---+---+---+---+---+---+---+---+---+---+ |
+---+---+---+---+---+---+---+---+---+---+---+ |
||
</pre> |
|||
=={{header|Uiua}}== |
|||
Just add the following lines to the end of [https://rosettacode.org/wiki/Maze_generation#Uiua the generator]. It shows you the maze that has been solved with the path highlighted, the list of moves, and the total path length. |
|||
<syntaxhighlight lang="uiua"> |
|||
# S O L V E T H E M A Z E # |
|||
. |
|||
Start ← 1_1 |
|||
End ← -Start ×2 H_W |
|||
Heur ← /+⌵-End # Manhattan distance. |
|||
# (pos grid) -> 1-4 next steps, in bounds, without walls in the way. |
|||
Ns ← ≡⊡1▽:⟜(≡(=@ ⊡)⊙¤≡GetWall)≡⊟¤:InBounds Nfour. |
|||
astar(Ns|Heur|≍End) Start # Solve (costs = 1 => djikstra) |
|||
$"_ moves" ⊙⟜(⍜(⊡|+33)):°□⊢ |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
╭─ |
|||
╷ "+-+-+-+-+-+-+" |
|||
"|O O O|. O O|" |
|||
"+-+-+ + + + +" |
|||
"|.|O O|.|O|O|" |
|||
"+ + +-+-+ + +" |
|||
"|.|O O O O|O|" |
|||
"+ +-+-+-+-+ +" |
|||
"|. . . . . O|" |
|||
"+-+-+-+-+-+-+" |
|||
╯ |
|||
╭─ |
|||
╷ 1 1 |
|||
1 3 |
|||
1 5 |
|||
3 5 |
|||
3 3 |
|||
5 3 |
|||
5 5 |
|||
5 7 |
|||
5 9 |
|||
3 9 |
|||
1 9 |
|||
1 11 |
|||
3 11 |
|||
5 11 |
|||
7 11 |
|||
╯ |
|||
"14 moves" |
|||
</pre> |
</pre> |
||