Tower of Hanoi

Moves: 0En Az Moves: 7

Tap a peg, then tap the peg you want to move to

Category
Brain
Players
1
Controls
Tap / Tap
Rule
Never big on small
Loads
No install

Controls

Tap a pegPick up the top disc from it.
Tap another pegPlace the disc there if the move is legal.
New gameReset the discs to the starting peg.
Next up

More games

About this game

The Tower of Hanoi is a mathematical puzzle from 1883 that has been teaching people about recursion ever since. A stack of discs sits on one peg, largest at the bottom. Move the whole stack to another peg, one disc at a time, and never place a larger disc on a smaller one. That is all there is to it.

The elegance is that the puzzle has a perfect solution and a knowable minimum number of moves, and once you see the pattern you can solve any size of stack. Getting there is the fun: most people flounder for a while, then suddenly notice that moving a stack of five is just moving a stack of four twice with one move in between.

Tips & strategy

Think recursively. To move a stack of five, you first move the top four out of the way, move the biggest disc across, then move those four on top of it. Every size of puzzle reduces to a slightly smaller version of itself, and that insight solves the whole thing.

Watch the smallest disc. In the optimal solution it moves every other turn, always in the same rotational direction around the pegs. If you keep the little one circling steadily and make the only legal move in between, you are playing perfectly without having to calculate anything.

Know your target. The minimum number of moves is always one less than two to the power of the number of discs, so three discs need seven moves and five need thirty-one. Knowing the number tells you immediately whether you are on the optimal path or wandering.

Do not undo your own work. The most common mistake is moving a disc back where it came from a turn later, which wastes two moves and usually means you had no plan. If you find yourself shuffling the same disc back and forth, stop and think about which peg the big disc needs to reach.

Questions

What is the one rule?

A larger disc may never rest on a smaller one. Everything else follows from that.

What is the fewest possible moves?

Two to the power of the number of discs, minus one. Seven for three discs, fifteen for four, thirty-one for five.

Is there always a solution?

Yes, and a perfect one. The puzzle is completely solvable for any number of discs.

Why is this puzzle famous?

It is the classic teaching example of recursion in mathematics and computer science, because the solution contains a smaller copy of itself.

Is it really free?

Completely free, with no trial and no unlock. Tower of Hanoi loads with the page and plays immediately, without an install step or a video ad first.