Taroimo Science Lab日本語

All simulationsMenu

← All simulations

The Tower of Hanoi and Recursion

Exaggerated displayPlay

Move disks one at a time to restack them on another peg. Solve it yourself and compare with the fewest moves, or watch the shortest solution built by recursion, together with the pile of calls known as the call stack. It solves optimally from any arrangement.

  • Drag the top disk to another peg. You can also tap a disk, then tap the destination peg.
  • Press "Solve in fewest moves" to watch the shortest solution from the current arrangement. The call stack, the pile of recursive calls, appears on the right.
  • Press "One move" to advance one move at a time; you can also pause and change the speed in the toolbar.
  • Under "Starting arrangement", choose the standard puzzle, a random arrangement, or small, medium and large disks on separate pegs. "Goal peg" sets where the disks should end up. "Left peg" and "Any peg" are not available when all disks start on the left, since they are already gathered there.
  • Press "Merge from the smallest" to compare another way of solving, which is not always shortest, with the fewest moves.
  • See the moves so far and the fewest moves for the tower on screen under "Moves for the tower on screen".
  • Use "Number of disks (calculation only)" to see the minimum 2n−12^n - 1 for up to 64 disks and how long it would take at one move per second. Both are calculated values, separate from the tower on screen.