Figure %: Towers Solution for 1 disc

Two Discs

Let's make the problem slightly bigger. Imagine two discs.

Figure %: Towers Problem with 2 Discs

How do we solve this problem? Simple, again.

  1. Use the one disc solution to move the top disc to the intermediate pole.
  2. Use the one disc solution to move the bottom disc to the final pole.
  3. Use the one disc solution to move the top disc to the final pole.

Figure %: Towers Solution for 2 Discs

Three Discs

How about with three discs?

  1. Use the two disc solution to move the top discs to the intermediate pole.
  2. Use the one disc solution to move the bottom disc to the final pole.
  3. Use the two disc solution to move the top discs to the final pole.

N Discs

So how about with N Discs?

  1. Use the N - 1 disc solution to move the top discs to the intermediate pole.
  2. Use the one disc solution to move the bottom disc to the final pole.
  3. Use the N - 1 disc solution to move the top discs to the final pole.

Figure %: Towers Solution for N discs

And, voila! A recursive solution to solving the Towers of Hanoi! Note that the problem can be solved iteratively as well; however it makes much more intuitive sense recursively.

Now that we know how to solve an n-disc problem, let's turn this into an algorithm we can use.