64 discs until the end of the world

Towers of Hanoi

Discs–
Moves0
Time0:00
Best–

Tap a peg to pick up its top disc, then tap the peg it should go to. On a computer you can also use the keys 1, 2 and 3.

Background

The legend

In the temple of Benares, so the legend goes, Brahmins have been moving the sacred tower of Brahma since time immemorial: 64 discs of fine gold, set with diamonds. They follow the same two rules as you do. When the last move is made, tower and temple will crumble, and the world will end.

Don’t worry. Even at one move per second, without a break and without a mistake, they would need 18,446,744,073,709,551,615 moves, about 585 billion years. That is more than 40 times the age of the universe.

Where the game comes from

It was invented by the French mathematician Édouard Lucas. In 1883 he put it on sale as an “authentic brain teaser of the Annamites, brought back from Tonkin”, supposedly discovered by a “Professor N. Claus (de Siam)”. The name is an anagram of “Lucas d’Amiens”, because Lucas came from Amiens.

Tonkin is the north of present-day Vietnam, around Hanoi. Lucas supplied the temple legend himself, on the cover of the game. So the puzzle shares little more than its name with Hanoi.

Why 2n − 1 moves?

To move the bottom disc, the whole tower above it first has to move away, onto the free peg. Then the large disc goes to the goal, and the smaller tower has to go back on top.

So moving n discs means solving the n − 1 puzzle twice, with one move in between. Every extra disc doubles the effort, plus one:

2n − 1

1 disc: 1 · 2: 3 · 3: 7 · 4: 15 · 5: 31 · 6: 63 · 10: 1,023 · 20: 1,048,575

Fewer moves are impossible, and this can be proven mathematically. Reducing a problem to a smaller version of itself is called recursion.

The practical trick

The smallest disc moves every other turn, always in a circle in the same direction. With an odd number of discs it goes Start → Goal → Middle → Start, with an even number Start → Middle → Goal → Start.

In between there is always exactly one legal move that doesn’t involve the smallest disc. That’s all you need to remember.

It counts in binary

Which disc moves on which turn is given by the move number in binary: count the zeros at the end and add one. Move 1 (binary 1) moves disc 1, move 2 (10) disc 2, move 4 (100) disc 3, move 6 (110) disc 2 again.

Where else you’ll meet it

In computer science it is the classic example of recursion. In psychology it is used to test planning ahead. And if you draw all possible positions as a network, you get the Sierpiński triangle, a fractal.