GridPencil
05

Tower of Hanoi

Move a stack of discs from the left peg to the right, one at a time, never placing a larger disc on a smaller one.

About Tower of Hanoi

The Tower of Hanoi was published by the French mathematician Édouard Lucas in 1883 and has been a favourite of maths teachers ever since. It looks like a toy. It is really a lesson in breaking a big problem into smaller copies of itself.

How it works

You can choose three, four, five or six discs. The fewest moves needed doubles and adds one with each extra disc: 7, 15, 31 and 63. The counter shows your moves beside that target, so you always know how efficient you are being.

The method

To move a stack of four discs to the right, you must first get the top three out of the way onto the middle peg, then move the big disc across, then bring the three back on top of it. Moving three discs is the same problem again, one size smaller. That idea, repeated, solves any tower.

In practice there is a simple rhythm. The smallest disc moves on every other turn, and it always travels in the same direction round the three pegs. With an even number of discs, send it to the middle peg first. With an odd number, send it to the right. On the turns in between, there is only ever one legal move that does not involve the smallest disc, so make it.

If you lose your place, look for the largest disc that is not yet home and ask what must happen before it can move.

Three discs is a warm-up. Six is 63 moves and a real test of concentration. As HTML5 games go it is ancient in spirit and still one of the most satisfying to finish perfectly.