Tower of Hanoi

Tap a peg to lift its top disk, then tap another peg to drop it. A larger disk never rests on a smaller one. Move them all to the right-hand peg to finish; the fewest possible moves sits on screen so you can see how many extra you spent.

Moves0
Fewest7

Tap a peg to lift its top disk, then tap another peg to drop it. A larger disk never goes on a smaller one. Keys 1, 2 and 3 work too.

Only legal moves are counted

Choosing a disk count also shows the fewest moves: 7 for 3 disks, 31 for 5, 255 for 8. Trying to drop a larger disk on a smaller one does nothing and adds nothing. Tapping the peg you lifted from cancels the pick-up, and that is not counted either. There is no undo — a wrong move is one, and moving it back is another, so a slip costs two. Time is not measured. What matters in this puzzle is the count.

The smallest disk always has one place to go

There is exactly one shortest route, and it takes two lines to remember. On every odd-numbered move, move the smallest disk, and always rotate it the same way — with an odd number of disks it goes left→right→middle→left, with an even number left→middle→right→left. On every even-numbered move there is exactly one legal move that does not involve the smallest disk, so there is nothing to choose. That is why the first move goes right with 3 disks and to the middle with 4. The automatic solver plays this sequence one move every 0.32 seconds.

Records are kept per disk count

When all disks are across, the result is compared with the record for that disk count and replaces it only if it is lower. A 7 with 3 disks does not touch the 4-disk record. Records stay in this browser and are not sent anywhere. A board finished by the automatic solver is not recorded — the disks really move, but only hand-played boards count.

Common questions

QWhat is the fewest possible number of moves?

For n disks, 2ⁿ − 1. Three disks take 7, four take 15, five take 31, ten take 1,023. Moving n disks means setting the top n−1 aside, moving the largest, then stacking them back — so f(n) = 2·f(n−1) + 1.

QIs that really the minimum? Could something beat it?

It cannot. Rather than trust the remembered formula, every reachable position up to 9 disks was swept. There are 3ⁿ positions for n disks; spreading outward one move at a time reached all 3ⁿ, and the distance to the finished position matched 2ⁿ − 1 every time.

QHow does "solve it for me" play?

It plays the shortest sequence. That sequence was replayed move by move for 1 through 14 disks to confirm no move breaks the rules and the tower always ends up moved — 14 disks takes 16,383 moves.

QWhy stop at 8 disks?

Eight disks already need 255 moves, and beyond that a game stops being playable by hand: ten need 1,023 and twenty need over a million. The 64 disks of the legend would take 2⁶⁴ − 1, about 18.4 quintillion.

QCan a disk go to any peg?

Yes, any of the three. The middle peg is where things wait, and getting the fewest moves is entirely a matter of how you use it.

QCan I finish on the middle peg instead?

It does not count as finished. The game ends only when every disk is on the right peg. Stacking them on the middle peg breaks no rule, so the moves are counted, but moving the stack on to the right peg then costs the minimum all over again.

QI used more than the minimum. Can I tell where I went wrong?

The screen does not say. But you only need to watch the smallest disk: every time it rotates the wrong way, two moves are wasted right there. If you are 2, 4 or 6 over the minimum, that is almost always the cause.

Source last checked: 2026-08-20