Skip to content
PixelCursor(opens in a new tab)
Games

Towers of Hanoi

Interactive visualization of the recursive puzzle

3 discs · Easy
Speed
Solver
Game

Move the whole tower to C

One disc at a time, never a bigger one on a smaller one.

Click a peg or press 1, 2, 3 to lift its top disc.

Why this move?

The solver thinks recursively: before a disc can reach its goal, every smaller disc has to get out of the way onto the third peg. The same rule then applies to those smaller discs.

  1. 3Disc 3 has to go from A to C.First discs 1 to 2 have to wait on B.
  2. 2Disc 2 has to go from A to B.First disc 1 has to wait on C.
  3. 1Disc 1 has to go from A to C.Next move

The next moves

  1. 1AC
  2. 2AB
  3. 1CB
  4. 3AC
  5. 1BA
  6. 2BC
  7. 1AC

Every disc doubles the work

n discs need at least 2ⁿ − 1 moves: move n − 1 discs aside, the biggest one once, then the n − 1 discs back on top of it.

With 64 discs, as in the legend: 18,446,744,073,709,551,615 moves. At one move per second that is about 585 billion years.

About this tool

  • A puzzle with a legend

    The French mathematician Édouard Lucas published it in 1883, together with a story about priests moving 64 golden discs. When they finish, the world ends.

  • 2ⁿ − 1 moves, never fewer

    The biggest disc has to move at least once, and before and after that all the others have to move as a whole. That is why each extra disc doubles the work and adds one.

  • The smallest disc keeps going round

    In the shortest solution the smallest disc moves on every second move, always round the pegs in the same direction. Watch it in the move list.

Keyboard

123
Lift or drop a disc on peg A, B or C
Space
Solver on or off
→
Next optimal move
←
Undo the last move
H
Show a hint
S
Scramble the discs
R
Start over
+-
More or fewer discs