Drexel dragonThe Math ForumDonate to the Math Forum

Ask Dr. Math: FAQ

  Tower of Hanoi  

_____________________________________________
Dr. Math FAQ || Classic Problems || Formulas || Search Dr. Math || Dr. Math Home
_____________________________________________

According to the legend of the Tower of Hanoi (originally the "Tower of Brahma" in a temple in the Indian city of Benares), the temple priests are to transfer a tower consisting of 64 fragile disks of gold from one part of the temple to another, one disk at a time. The disks are arranged in order, no two of them the same size, with the largest on the bottom and the smallest on top. Because of their fragility, a larger disk may never be placed on a smaller one, and there is only one intermediate location where disks can be temporarily placed. It is said that before the priests complete their task the temple will crumble into dust and the world will vanish in a clap of thunder.

Does this make mathematical sense?

In the classic math problem, there are three posts. Disks of different sizes (call the number of disks "n") are placed on the lefthand post, arranged by size with the smallest on top. You are to transfer all the disks to the righthand post in the fewest possible moves, without ever placing a larger disk on a smaller one. One move is considered to be moving one disk from one post to another post.

How many moves will it take to transfer n disks from the left post to the right post?



Let's look for a pattern in the number of steps it takes to move just one, two, or three disks. We'll number the disks starting with disk 1 on the bottom.

1 disk: 1 move

    Move 1: move disk 1 to post C

   



2 disks: 3 moves

    Move 1: move disk 2 to post B
    Move 2: move disk 1 to post C
    Move 3: move disk 2 to post C

   



3 disks: 7 moves

    Move 1: move disk 3 to post C
    Move 2: move disk 2 to post B
    Move 3: move disk 3 to post B
    Move 4: move disk 1 to post C
    Move 5: move disk 3 to post A
    Move 6: move disk 2 to post C
    Move 7: move disk 3 to post C
   



Can you work through the moves for transferring 4 disks? It should take you 15 moves. How about 5 disks? 6 disks? Do you see a pattern?



A. Recursive pattern

From the moves necessary to transfer one, two, and three disks, we can find a recursive pattern - a pattern that uses information from one step to find the next step - for moving n disks from post A to post C:

  1. First, transfer n-1 disks from post A to post B. The number of moves will be the same as those needed to transfer n-1 disks from post A to post C. Call this number M moves. [As you can see above, with three disks it takes 3 moves to transfer two disks (n-1) from post A to post C.]

  2. Next, transfer disk 1 to post C [1 move].

  3. Finally, transfer the remaining n-1 disks from post B to post C. [Again, the number of moves will be the same as those needed to transfer n-1 disks from post A to post C, or M moves.]

Therefore the number of moves needed to transfer n disks from post A to post C is 2M+1, where M is the number of moves needed to transfer n-1 disks from post A to post C.

Unfortunately, if we want to know how many moves it will take to transfer 100 disks from post A to post B, we will first have to find the moves it takes to transfer 99 disks, 98 disks, and so on. Therefore the recursive pattern will not be much help in finding the time it would take to transfer all the disks.

However, the recursive pattern can help us generate more numbers to find an explicit (non-recursive) pattern. Here's how to find the number of moves needed to transfer larger numbers of disks from post A to post C, remembering that M = the number of moves needed to transfer n-1 disks from post A to post C:

  1. for 1 disk it takes 1 move to transfer 1 disk from post A to post C;

  2. for 2 disks, it will take 3 moves:    2M + 1 = 2(1)  + 1 =  3

  3. for 3 disks, it will take 7 moves:    2M + 1 = 2(3)  + 1 =  7

  4. for 4 disks, it will take 15 moves:   2M + 1 = 2(7)  + 1 = 15

  5. for 5 disks, it will take 31 moves:   2M + 1 = 2(15) + 1 = 31

  6. for 6 disks... ?



B. Explicit Pattern

    Number of Disks         Number of Moves
            1                          1
            2                          3
            3                          7
            4                         15
            5                         31

    Powers of two help reveal the pattern:

    Number of Disks (n)     Number of Moves
            1                 2^1 - 1 = 2 - 1 = 1
            2                 2^2 - 1 = 4 - 1 = 3
            3                 2^3 - 1 = 8 - 1 = 7
            4                 2^4 - 1 = 16 - 1 = 15
            5                 2^5 - 1 = 32 - 1 = 31

So the formula for finding the number of steps it takes to transfer n disks from post A to post B is: 2^n - 1.

From this formula you can see that even if it only takes the monks one second to make each move, it will be 2^64 - 1 seconds before the world will end. This is 590,000,000,000 years (that's 590 billion years) - far, far longer than some scientists estimate the solar system will last. That's a really long time!



From the Dr. Math archives

On the Web

Submit your own question to Dr. Math

[Privacy Policy] [Terms of Use]

_____________________________________
Math Forum Home || Math Library || Quick Reference || Math Forum Search
_____________________________________

Ask Dr. Math ®
© 1994-2014 Drexel University. All rights reserved.
http://mathforum.org/
The Math Forum is a research and educational enterprise of the Drexel University School of Education.The Math Forum is a research and educational enterprise of the Drexel University School of Education.