Hacker News new | ask | show | jobs
by efavdb 8 days ago
My three year old taught me something he saw on a YouTube video: you can search through a maze and find your way out just by keeping your right hand on the wall at all times and continuing till exit. Does a DFS.
5 comments

This only works for two dimensional mazes where both the entrance and exit are on an edge and there are no loops in the maze.

If you introduce a bridge, or a tunnel, or put the goal in the middle, you can get stuck in a loop.

Another nifty maze solving trick: Using flood-fill in Paint or some such, starting at the entrance, paint the wall on one side of the entrance red, and the other blue. You'll find that the border between the red and blue sections (the path where one wall is red and the other is blue) is the path to the exit. If there are loops, then you'll end up with uncolored squares, but you can just treat those as blue if you follow the red edge.
A nice case of an algorithm being easier to learn physically than abstractly
Throw a loop/island in the maze and see how your kid reacts.
I vaguely recall a windows screensaver that did this