Skip to content
One Quick Try

Tower of Hanoi

Move the whole stack to the last peg, one disk at a time, never a big disk on a small one.

Type
Logic
Takes
about 1-5 min
Result in
moves

Tower of Hanoi

~1-5 min

  1. Move the whole stack from the left peg to the right peg.
  2. Move one disk at a time: tap a peg to lift its top disk, then tap where it goes.
  3. A disk can never sit on a smaller one.
Disks

1 2 3 work too. The clock starts on your first move.

Your result: — moves

How it's measured
  • River Crossing

    Get everyone across the river safely.~2-5 min
  • Lights Out

    Turn off every light. Each press flips its neighbors.~1-3 min
  • Box Pushing

    Push every box onto a target.~2-10 min
  • Chinese Rings

    Take every ring off the bar.~2-5 min
  • Peg Solitaire

    Jump pegs until only one is left.~3-6 min
  • Bridge and Torch

    Get everyone across the bridge in 17 minutes.~2-4 min

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 disks4 disks5 disks6 disks7 disks
Perfect7153163127
Excellent816–1732–3564–72128–146
Good918–2036–4173–85147–171
Fair10–1221–2742–5586–113172–228
Keep trying13+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.

DisksFewest moves
37
415
531
663
7127

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.

Questions

How many disks should I start with?
4 disks takes 15 moves at best and is a good first try. Each extra disk roughly doubles the length, so 7 disks needs at least 127 moves.
Does the clock start when I press Start?
No, on your first move. Time spent looking at the puzzle before you begin is free.
Do illegal moves count?
No. A disk can't be put on a smaller one, so the move doesn't happen and your move count stays the same.
Can I move the stack to the middle peg instead?
Not here. The puzzle is solved only when every disk is on the right-hand peg.
How do you solve the Tower of Hanoi with 5, 6 or 7 disks?
The same way as with any number: move the smallest disk on every other move, always the same way round, and make the only other legal move in between. It takes 31, 63 and 127 moves at best for 5, 6 and 7 disks.
What is the difference between the Tower of Hanoi and the Tower of London?
The Tower of London is a planning test based on the Tower of Hanoi, devised by the neuropsychologist Tim Shallice in 1982. It uses balls of the same size on pegs of different heights, and asks you to reach a goal arrangement in a set number of moves. It is used in clinical neuropsychology; the Tower of Hanoi here is a puzzle.
Is there a simple way to solve the Tower of Hanoi?
Yes, without any planning: alternate between moving the smallest disk one peg along, always in the same direction round the three pegs (to the right with an even number of disks, to the left with an odd number), and making the only legal move that doesn't use the smallest disk. It always finishes in the fewest moves, 2ⁿ − 1; the site's tests check it for 3 to 8 disks.