Tower of Hanoi: Play the Puzzle Online

Play the Tower of Hanoi puzzle online with 3 to 8 disks. Move the tower in the fewest moves, track your best, or watch the solution step by step.

Loading…

The Tower of Hanoi is a classic logic puzzle. Move the whole stack of disks from the left peg to the right peg, one disk at a time, never putting a larger disk on a smaller one. With three disks it takes seven moves; every extra disk doubles the work, and eight disks need 255 moves. Tap a peg to lift its top disk, then tap the peg to put it on. The move counter shows how you compare with the fewest moves possible, your best for each number of disks saves, and Show the solution plays the shortest answer one move at a time so you can see the pattern. It runs in your browser with nothing to install and no account, on a computer, tablet or phone.

Common use cases

  • Solve a classic logic puzzle on a break
  • Teach recursion and problem solving in class
  • Learn to plan several moves ahead
  • See the shortest solution played out

How to use

  1. Choose how many disks to start with (3 to 8).
  2. Tap a peg to pick up its top disk, then tap another peg to place it.
  3. Never put a bigger disk on a smaller one.
  4. Move the whole tower to the right peg. Try to match the fewest moves.

FAQ

What is the minimum number of moves for the Tower of Hanoi?

2 to the power of the number of disks, minus 1. Three disks take 7 moves, four take 15, five take 31, six take 63, seven take 127 and eight take 255.

What is the trick to solving the Tower of Hanoi?

To move a stack of n disks, move the top n − 1 disks out of the way, move the biggest disk, then move the n − 1 disks back on top of it. In practice, move the smallest disk every other turn, always in the same direction around the pegs, and make the only other legal move in between.

Why is the Tower of Hanoi used to teach recursion?

Its solution is the textbook example of solving a problem by breaking it into smaller copies of itself, which is exactly what a recursive function does.

Is there a legend behind the Tower of Hanoi?

The puzzle was published in 1883 by the French mathematician Édouard Lucas, with a story about monks moving 64 golden disks. At one move a second, 64 disks would take about 585 billion years.