Tower of Hanoi Solver
What this gives you
Every move, in order, for up to twelve discs, with the stacks drawn as they go. Press Play to watch it, Step to walk it one move at a time, or click any move in the list to jump straight to that position. Back takes a move off again, which is the part a printed list cannot do.
The disc numbers are by size, so disc 1 is the smallest. A move reads as the disc and the two pegs, for instance disc 1 from A to C.
Why the move count is what it is
To move a stack of n discs you have to get the top n minus 1 out of the way onto the spare peg, move the bottom disc across, then bring that pile back on top. That is twice the work of an n minus 1 stack plus one move, so the counts run 1, 3, 7, 15, 31 and so on: two to the power of n, minus one.
Nothing cleverer exists. The sequence is forced by the rules rather than being the best anyone has found, which is rare in a puzzle and is why this one has been taught for a hundred and forty years. The tool states the count it produced and the number it should be, so you can see the two agree rather than take it on trust.
Twelve discs is 4,095 moves. The legend of sixty four discs is 18,446,744,073,709,551,615, which at one move a second is around 585 billion years.
Solving it yourself
There is a rule that needs no recursion at all. Number the discs by size and alternate: on odd moves, move disc 1 one peg along, always in the same direction, wrapping round at the end. On even moves, make the only legal move that does not involve disc 1. That produces exactly the sequence this tool prints.
Which direction disc 1 should travel depends on whether you started with an odd or an even number of discs. If you find yourself undoing your own work, you picked the wrong one.
There is a fuller write-up in the Tower of Hanoi: history, strategy and best moves, and a daily Tower of Hanoi to play with a different number of discs each day.
The puzzle itself is a 3D printed travel set in the shop, small enough for a pocket, and it sits with the rest of the mechanical puzzles.
Frequently Asked Questions
What is the minimum number of moves for the Tower of Hanoi?
Two to the power of the number of discs, minus one. The sequence runs 1, 3, 7, 15, 31 and so on, and nothing cleverer exists because the rules force it.
How many moves does a 7 disc Tower of Hanoi take?
127 moves, which is 2 to the power 7 minus 1. A 10 disc tower takes 1,023.
Is there a trick to the Tower of Hanoi?
Think about the biggest disc. Nothing may ever rest on it, so before it can move, every other disc has to be stacked out of its way on the spare peg. That turns the puzzle into the same puzzle with one disc fewer, which is why the count doubles each time you add one.