한국어

Tower of Hanoi

Move the whole tower to the right peg, one disk at a time

Move every disk to peg 3

One disk at a time, and never a bigger disk on a smaller one. Pick anywhere from 3 to 10 disks.

Controls

Tap a peg to pick up its top disk, tap another to drop it
Or drag a disk across
Keys 1 · 2 · 3: choose a peg
Undo (Z) · Restart (R) · Auto solve (A)

How do you play the Tower of Hanoi?

You win by moving the stack of disks from the left peg to the right peg, one disk at a time, so it ends up in the same order. A bigger disk may never sit on a smaller one.

The French mathematician Édouard Lucas published the puzzle in 1883, and it is still the go-to first example of recursion in math and programming classes.

What are the rules?

What is the minimum number of moves?

With n disks the fewest possible moves is 2n - 1. That is 7 moves for 3 disks and 1,023 for 10.

Think about the biggest disk. Before it can go to the right peg, the n - 1 smaller disks on top of it have to be parked on the middle peg. Then the big disk moves once, and the n - 1 small disks come back on top of it. So n disks take twice the moves for n - 1 disks, plus one. One disk takes 1 move, two take 3, three take 7, four take 15, and the pattern works out to 2n - 1. The biggest disk can only move when every smaller disk is out of the way, so there is no shorter route.

DisksFewest moves
37
415
531
663
7127
8255
9511
101,023

How do you solve it in the fewest moves?

  1. Pick the first move by the number of disks. With an odd number, move the smallest disk to the goal peg first. With an even number, move it to the middle peg.
  2. The smallest disk moves every other turn, always cycling in the same direction.
  3. On the turns in between there is only one legal move that leaves the smallest disk alone. Make it.
  4. When lost, think about the biggest disk. To move it, everything above it has to be gathered on one other peg.

How does auto solve work?

It finishes the puzzle from wherever the disks are right now, in the fewest possible moves. You can set the speed from 1x to 16x, and from the start it takes exactly 2n - 1 moves.

It follows the same idea as above. If the biggest disk is not on the goal peg yet, the smaller disks are cleared to the spare peg, the big disk moves, and the smaller disks follow it. Moving the smaller disks repeats the same plan one size down.

Legend says the world ends when monks finish moving a tower of 64 disks. That takes 264 - 1 moves, about 18 quintillion, or roughly 585 billion years at one move per second. Games that used auto solve are not saved as records. Your best result for each number of disks is saved in this browser.

Frequently asked questions

Is the Tower of Hanoi free to play?

Yes. Play it free right on this page with no sign up, on computers, phones and tablets.

What is the minimum number of moves for n disks?

It is 2 to the power of n, minus 1. That is 7 moves for 3 disks, 31 for 5 and 1,023 for 10.

Why is it 2^n - 1?

To move the biggest disk you have to park the n - 1 smaller disks on another peg and then bring them back, so n disks take twice the moves of n - 1 disks plus one. Starting from one disk that gives 1, 3, 7, 15 and so on, which is 2^n - 1.

What happens if I try to put a big disk on a small one?

It will not drop there and goes back to its peg. A disk can only go on an empty peg or on a larger disk.

How do I earn stars?

Three stars for solving in the fewest possible moves, two for staying within 1.5 times that, and one for anything more.

Does auto solve count toward my records?

No. A game where auto solve was used is not saved as a record. You can still watch the fewest move solution from the current position at 1x to 16x speed.

Can I play with a keyboard?

Yes. Press 1, 2 or 3 to pick the peg to lift from, then the peg to drop on. Z undoes, R restarts and A starts auto solve.