The rules
- All the disks start on the left peg, largest at the bottom.
- Move them all to the right peg.
- Move one disk at a time, and only the top disk of a peg.
- Never put a disk on top of a smaller one.
How do you play the Tower of Hanoi?
Pick 3 to 7 disks (4 is a good start). Tap a peg to lift its top disk, then tap the peg where it should go. Tap the same peg again to put the disk back down. On a keyboard, 1, 2 and 3 tap the three pegs and Escape puts a lifted disk back. An illegal move doesn't count: the disk stays where it was and you see why.
How is your Tower of Hanoi result calculated?
The clock starts on your first move, not when you press Start, so you can look at the puzzle and plan first. It stops on the move that completes the stack. You see your time, your number of moves, and the fewest moves possible for that many disks. Matching the minimum means you found the perfect solution.
What does my Tower of Hanoi rating mean?
The rating compares your moves with the fewest possible, so it needs no averages: exactly the fewest is Perfect, and the more moves you add, the lower the rating. The moves that earn each rating:
| Rating (moves) | 3 disks | 4 disks | 5 disks | 6 disks | 7 disks |
|---|---|---|---|---|---|
| Perfect | 7 | 15 | 31 | 63 | 127 |
| Excellent | 8 | 16–17 | 32–35 | 64–72 | 128–146 |
| Good | 9 | 18–20 | 36–41 | 73–85 | 147–171 |
| Fair | 10–12 | 21–27 | 42–55 | 86–113 | 172–228 |
| Keep trying | 13+ | 28+ | 56+ | 114+ | 229+ |
The fewest moves
The minimum for n disks is 2n − 1. The reason is neat: to move the bottom disk, every other disk must first be moved out of the way onto the middle peg, which is the same puzzle with one disk fewer. Then the bottom disk moves once, and the smaller stack moves again on top of it. So each extra disk doubles the work and adds one move.
| Disks | Fewest moves |
|---|---|
| 3 | 7 |
| 4 | 15 |
| 5 | 31 |
| 6 | 63 |
| 7 | 127 |
Is there a strategy that always solves the Tower of Hanoi?
Move the smallest disk on every other move, always in the same direction around the pegs. With an odd number of disks it goes left peg, right peg, middle peg, left peg and so on. With an even number it goes left, middle, right. On the moves in between, make the only legal move that doesn't involve the smallest disk. Follow that and you solve it in the minimum number of moves.
The legend
The puzzle was invented by the French mathematician Édouard Lucas in 1883, and sold with a story about priests moving a tower of 64 golden disks, with the world ending when they finished. At one move per second, 264 − 1 moves would take about 585 billion years.
Lucas tells the story himself in the third volume of his Récréations mathématiques (1893), credited to a “mandarin N. Claus (de Siam)”, whose name is an anagram of Lucas d'Amiens. In the great temple at Benares, 64 disks of pure gold sit on one of three diamond needles, and priests work day and night to move them to the third: “when all is done, the tower and the Brahmins will fall, and it will be the end of the worlds.” He also points out that the number of moves equals the number of grains of wheat in the old story of the chessboard, where the grains double on each of the 64 squares.
Is the Tower of Hanoi used in psychology?
Yes. Psychologists use it to study how people plan and solve problems, as in Kenneth Kotovsky, John Hayes and Herbert Simon's “Why are some problems hard? Evidence from Tower of Hanoi” (1985). A related clinical test, the Tower of London, was designed by Tim Shallice in 1982 as a task that leans heavily on planning. In his study, patients with damage to the front of the left side of the brain had a specific difficulty with it.
Want another puzzle that rewards planning ahead? Try the River Crossing Puzzle or Make 24.