Tower of Hanoi Online

Move the whole stack to the last peg, one disc at a time, never a bigger disc on a smaller one

The Tower of Hanoi is a classic planning puzzle with three pegs and a stack of discs of different sizes. All the discs start on the first peg, largest at the bottom. You must move the whole stack to the last peg, moving one disc at a time, taking only the top disc of a peg, and never putting a disc on top of a smaller one. With n discs the fewest possible moves is 2 to the power n, minus 1: 7 moves for 3 discs, 15 for 4 and 255 for 8. Ours offers 3 to 8 discs, a Scrambled start that spreads the discs over the pegs, a move counter against the fewest possible moves, and a Hint button that always shows a move from a shortest solution.

How to play

Choose how many discs, from 3 to 8. More discs means many more moves: each extra disc roughly doubles the work.

Choose the start. Classic stacks every disc on peg A. Scrambled spreads the discs over all three pegs in a random legal position and tells you the fewest moves from there when you start.

Press Start. The goal is peg C, marked with a target.

Tap a peg to pick up its top disc, then tap the peg where it should go. Tap the same peg again to put it back.

A disc may only go on an empty peg or on a bigger disc; the game refuses any other move and says why.

Hint highlights the next move of a shortest solution from wherever you are: amber is the peg to take from, green the peg to put on. Undo takes back a move but still counts as one, so the move count stays honest.

On a keyboard, press 1, 2 and 3 to pick pegs A, B and C, H for a hint and Ctrl+Z to undo. Gather every disc on C to finish; your fewest moves for that disc count and start are saved.

What it actually trains

Planning and goal management. Moving a big disc requires first moving every smaller disc out of the way, which in turn requires moving the ones above them, so the puzzle trains breaking a goal into sub-goals and holding that plan in mind while acting. Psychologists have long used tower tasks of this kind (the Tower of Hanoi and its relatives such as the Tower of London) to study planning and executive function, and the move count compared with the minimum is a direct measure of how efficient the plan was. Another logic game to try next: Knight's Tour. For a grid puzzle with a single answer, try Hitori.

Tips to score higher

The smallest disc moves on every other turn. In a classic start, move it in a steady cycle: with an odd number of discs A to C to B to A, with an even number A to B to C to A.

On the turns between, there is only ever one legal move that does not touch the smallest disc. Make it.

Think recursively: to move the bottom disc of n, first move the top n − 1 discs to the spare peg, then the big disc, then the n − 1 discs on top of it.

From a scrambled start, look at the largest disc that is not yet on C. Everything smaller has to gather on the third peg before it can move.

If you are over the move count, use Hint once to see where a shortest solution goes, then carry on yourself.

Learn on 3 and 4 discs until you can do them in 7 and 15 moves without hints, then step up one disc at a time.

Frequently asked questions

What is the Tower of Hanoi?

It is a puzzle with three pegs and a stack of discs that get smaller toward the top. You move the whole stack from one peg to another, one disc at a time, moving only top discs, and never placing a disc on a smaller one.

What is the minimum number of moves?

For n discs the fewest moves is 2^n − 1: 7 for 3 discs, 15 for 4, 31 for 5, 63 for 6, 127 for 7 and 255 for 8. The game shows that number before you start a classic game.

How does the Hint button know the best move?

From any legal position it works from the largest disc down: a disc already on its goal peg stays, and the first disc that is not sends every smaller disc to the third peg. The move it shows is the first move of a shortest solution, and our tests check this against a full search of every position for up to 6 discs.

What is a scrambled start?

Instead of one neat stack, the discs begin spread over the three pegs in a random legal position, always at least a quarter of the classic minimum away from the goal. The fewest moves from that position is shown when you start.

Why does undo count as a move?

So that a finish in the fewest moves really means you planned it. Undo is still there to recover from a slip.

Is there a pattern to solve it?

Yes. Move the smallest disc every second turn in a fixed direction around the pegs, and on the other turns make the only legal move that does not use the smallest disc. That reaches the goal in the fewest moves from the classic start.

Is it free, and what is saved?

It is free with no sign-up. Your fewest moves for each disc count and start type, the number of towers solved and your last settings are saved in this browser only.