Number Maze Applet

Go to: Applet Instructions Algorithm

The Applet

Instructions

Click on the "North", "South", "East" and "West" buttons to move in those directions (North is up, East is right). Don't wander too far off the path.

Algorithm

There is a simple mathematical relationship between the numbers in each cell.

Direction Relationship
North Divide the number by 2.
(N -> N / 2)
South Multiply the number by 2.
(N -> N x 2)
East Multiply the number by 3 and add 1.
(N -> 3 x N + 1)
West Subtract 1 and divide the number by 3.
(N -> (N - 1) / 3)

Note that the pairs of transformations, N&S and E&W are inverses of each other. This means that paths can be reversed by reversing the individual steps in the reverse sequence, eg. {N,E,S,W} followed by {E,N,W,S}, will return to the original point. Changing the order of the reverse steps (which would be valid on a square grid) will get you lost.

When the maze is drawn, transitions between integers are shown as a yellowish path joining the squares. When the result wouldn't be an integer no path is drawn. For instance, if the centre square is 29 then South is 58 and East is 88. North, though, would be 14 1/2 and West would be 9 1/3. The square, 29 is then shown with paths leding South and East.

Note: In an ideal implementation it would always be possible to go South and East but this applet stops when the numbers get to around 4 million.