Tower of Hanoi 🗼
Move the whole tower to the right-hand peg. One disc at a time, and never a big disc on a small one.
Tap a peg to pick up its top disc, then tap where to put it.
Move the whole tower to the right-hand peg. One disc at a time, and never a big disc on a small one.
Tap a peg to pick up its top disc, then tap where to put it.
For n discs the fewest possible moves is 2ⁿ − 1. Each extra disc doubles the work and adds one:
| Discs | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|
| Minimum moves | 7 | 15 | 31 | 63 | 127 | 255 |
Think recursively. To move a tower of 4 discs from A to C, first move the top 3 out of the way to B, then move the biggest disc to C, then move the 3 from B on top of it. Moving the 3 uses exactly the same idea with 2, and so on.
There's also a simple pattern you can follow without thinking about recursion:
Our step-by-step explanation with diagrams is here: Tower of Hanoi Solution Explained.
The French mathematician Édouard Lucas published the puzzle in 1883. He added a legend of priests moving 64 golden discs between three diamond needles, with the world ending when they finished. With 64 discs the minimum is 2⁶⁴ − 1 = 18,446,744,073,709,551,615 moves. At one move per second that takes about 585 billion years, far longer than the age of the universe.
The Tower of Hanoi is a standard example in maths and computer science for teaching recursion, powers of two and planning ahead. Psychologists have also used versions of it in studies of problem-solving and planning. For more logic practice, try the Logic Puzzle or Minesweeper.