Tower of Hanoi solution: the trick that solves any size
The Tower of Hanoi is a puzzle with three pegs and a stack of disks of different sizes. It was invented by a French mathematician, Edouard Lucas, in 1883, and it is still used to teach planning and maths today.
The rules
All the disks start on the left peg, biggest at the bottom. The goal is to move the whole tower to another peg. You can move only one disk at a time, you can only move the top disk of a stack, and you can never put a bigger disk on top of a smaller one.
The 3-disk solution in 7 moves
Call the pegs A (start), B (middle) and C (goal). Number the disks 1 (smallest) to 3 (biggest).
1. Disk 1 from A to C. 2. Disk 2 from A to B. 3. Disk 1 from C to B. 4. Disk 3 from A to C. 5. Disk 1 from B to A. 6. Disk 2 from B to C. 7. Disk 1 from A to C.
The simple trick for any size
There is a pattern that solves every tower without thinking hard. Alternate between two kinds of move: move the smallest disk, then make the only other legal move that does not use the smallest disk. Repeat until you are done.
The smallest disk always travels in the same direction around the pegs. If you have an odd number of disks, it goes A to C to B to A, and so on. If you have an even number of disks, it goes A to B to C to A. Follow that, and the tower builds itself on peg C.
The fewest moves
The smallest number of moves for n disks is 2 to the power n, minus 1. That is 7 moves for 3 disks, 15 for 4, 31 for 5, 63 for 6 and 255 for 8. Every extra disk doubles the work, plus one.
Why it works
To move a tower of 4 disks, you first move the top 3 out of the way, then move the big disk, then move the 3 back on top. Moving 3 disks means moving 2 disks out of the way first, and so on. Mathematicians call this recursion: solving a big problem by solving a smaller copy of it.
The legend of the 64 disks
A famous story says that monks are moving a tower of 64 golden disks, and when they finish, the world will end. Do not worry: at one move per second, 2 to the power 64 minus 1 moves would take about 585 billion years.
Try it
Our Tower of Hanoi game starts small and adds disks as you go. Try the alternating trick and see if you can match the minimum number of moves.

