Computer science · Algorithms
Tower of Hanoi: ten levels
From 1 to 10 disks: play, observe recursion and try to reach the minimum number of moves.
Move all disks from A to C. Tap a peg to select its top disk, then tap the destination peg. Move only one disk at a time and never put a larger disk on a smaller one. Keyboard: Tab to choose a peg, Enter or Space to activate it.
Moves made—
Minimum from the start—
Minimum still needed—
Manual record on this device—
Manual game
Start and One step continue from your current position: a different choice does not require a restart. Pause lets the current move finish. Restart resets only the current game, not records.
This device does not support animation: moves are still available step by step.
Recent moves
- No moves yet.
The last 12 moves are shown; Undo lets you return all the way to the start of the game.
Levels completed manually
Manual records are saved only in this browser, when available. No account or score submission. All levels are already selectable.
Why is the minimum 2ⁿ − 1?
To move n disks from A to C, first free the largest disk by moving the n−1 disks above it to B. Then move disk n from A to C. Finally move the n−1 disks from B to C.
- Move n−1 disks from A to B, using C as the auxiliary peg.
- Move disk n from A to C.
- Move n−1 disks from B to C, using A as the auxiliary peg.
M(0) = 0
M(n) = 2 × M(n−1) + 1 = 2n − 1
The same problem reappears with one fewer disk: this is recursion. With zero disks, do nothing. Each added disk doubles the previous minimum and adds one move. Hints and the guided solution use the same recursive strategy, adapted to the current position.
| Disks | Minimum moves |
|---|---|
| 1 | 1 |
| 2 | 3 |
| 3 | 7 |
| 4 | 15 |
| 5 | 31 |
| 6 | 63 |
| 7 | 127 |
| 8 | 255 |
| 9 | 511 |
| 10 | 1023 |
Further reading: Princeton, recursion and the Tower of Hanoi