What Is It About the Tower of Hanoi?
The Tower of Hanoi puzzle was invented by the French mathematician Edouard Lucas in 1883.
In 1889 he also invented a game he called Dots and Boxes.
Since that time, many of us have played this as children to avoid classwork. We call the game Join the Dots.
What is the aim?
There are three start positions. Using a given number of discs or blocks of different size, the aim is to move all the blocks from one position to another in the minimum number of moves possible.
The example below shows the six possible aims using 5 blocks.
Rules for moving the blocks
1. Only one block may be moved at a time.
2. Only the topmost block can be moved.
3. A block can only be placed on top of a larger block.
Shown below are three moves that are not allowed.
Different religions have legends surrounding the puzzle. There is a legend about a Vietnamese temple with three posts surrounded by 64 bags of gold.Throughout the centuries, priests have been moving these bags according to the three rules we saw previously.
When the last move is completed, the world will end.
But don't worry!
Even if the priests make no errors and can move bags at a rate of one per second,
the minimum time it would take is 580 billion years!
Move three blocks
Shown below are the moves needed to move three blocks from position A to position C.
The number of moves needed for a given number of blocks can be determined by noticing the pattern in the answers.
Below is shown the number of moves needed to move from 1 up to 10 blocks from A to C.
Notice the pattern in the number of moves.
and so on.
This means to find the number of moves for the Nth block, we calculate 2×N+1.
This is known as recursive form.
We can see why we double and add 1 from the symmetry of the situation.
Suppose M moves are needed to shift N blocks from A to C.
For N + 1 blocks, we need M moves to move the top N blocks from A to C. Then 1 move is needed to move the largest block from A to C. Finally, another M moves is required to place the N - 1 blocks on top of the largest block in C.
This gives a total of M + 1 + M = 2M + 1.
Will it take the same number of moves to shift N blocks from A to B as to move from B to A or from C to B?
Yes! Convince yourself of this using symmetry.
The drawback with the recursive method to find the number of moves is that to determine, say, the number of moves needed to move 15 blocks from A to C, we must know the number of moves required to move 14 blocks.
The number of moves can be written using powers of two, as shown below.
This means that for N blocks, the minimum number of moves needed is 2N - 1.
Back to the priests
The priests are using 64 bags of gold. At a rate of 1 move each second, this will take
18, 446, 744, 073, 709, 600, 000 seconds
213, 503, 982, 334, 601 days
584, 942, 417, 355 years
Now you can appreciate why our world is safe. At least for the next 500 billion years!