Tower of Hanoi
Move the tower to the right-hand peg, one disc at a time.
How to play Tower of Hanoi
The Tower of Hanoi is a famous puzzle invented by the French mathematician Édouard Lucas in 1883. It has three pegs and a stack of discs of different sizes. At the start, all discs sit on the left peg, the biggest at the bottom.
Goal
Move the whole tower to the right-hand peg (peg C). Try to do it in the fewest moves.
Rules
- Move only one disc at a time.
- You can only take the top disc of a peg.
- A disc may go onto an empty peg or onto a larger disc. Never put a larger disc on a smaller one.
How to move
Tap a peg to lift its top disc, then tap the peg where it should go. You can also drag a disc with your mouse or finger and drop it on another peg. On a keyboard, press 1, 2 and 3 (or A, B and C) to pick and drop, or use the arrow keys and Enter. Undo takes back moves one at a time.
Minimum moves
With n discs, the shortest solution needs 2ⁿ − 1 moves: 7 moves for 3 discs, 15 for 4, and 255 for 8. The status bar shows your moves next to the minimum, and your best score for each tower size is saved.
Auto-solve demo
Press Auto-solve to watch the computer finish the puzzle from the current position in the fewest possible moves. Press it again to stop and take over. A puzzle finished with the demo does not count as your best score.
End of the game
The puzzle is solved when every disc is on peg C. Solving it in the minimum number of moves earns a perfect score. Want another classic? Try Peg Solitaire.
Strategy tips
- Think small first. To move a tower of 4 discs, move the top 3 out of the way, move the big disc, then move the 3 back on top.
- First move depends on the count. With an odd number of discs, move the smallest disc to the target peg first. With an even number, move it to the middle peg.
- The smallest disc cycles. In the best solution the smallest disc moves every second turn, always around the pegs in the same direction.
- Only one other move. On the turns between, there is only one legal move that does not use the smallest disc. Make that move.
- Watch the demo. The auto-solve demo shows the pattern clearly. Watch it once with 4 discs, then try 5 yourself.
Tower of Hanoi FAQ
What is the minimum number of moves?
For n discs the minimum is 2 to the power n, minus 1. That is 7 moves for 3 discs, 31 for 5 and 255 for 8.
Can I move discs to the middle peg to finish?
No. The goal is peg C on the right. The middle peg is only for helping along the way.
How does the auto-solve demo work?
It works out the shortest path from the current position and plays it move by move. You can stop it at any time.
Where does the puzzle come from?
It was invented by Édouard Lucas in 1883, with a legend about monks moving 64 golden discs in a temple.