What are the Towers of Hanoi?

Is the end of the world near? At a monastery in the city of Hanoi, Vietnam, a group of monks has made it their life's work to solve the Towers problem, known due to its location as the Towers of Hanoi. Legend has it that the world will end when the monks finally solve the puzzle.

The puzzle is this. In the monastery are 3 pegs made of diamond. Resting on these pegs are 64 discs made of solid gold. None of the 64 discs are the same size; in fact, disc 1 is slightly larger in diameter than disc 2, which is slightly larger in diameter than disc 3, which is slightly larger in diameter than disc 4, etc. The initial configuration of the puzzle has all 64 discs piled in order of size on the first peg with the largest disc on the bottom.

Figure %: Example Towers Configuration

To solve the puzzle, all 64 discs must be moved to the third peg. Easy you say? The problem is that due to the fragility of the gold, you are not allowed to rest a larger disc on top of a smaller one, and only one disc may be removed from the pegs at any one time.

Figure %: Moving a single disc

There are many ways to solve this problem. The first is purely guess and check. Those who fear the end of the world may be hoping that the monks are using this approach. However, they're not; in fact, the monks all know the exact sequence of moves to solve the problem.

Solving Towers of Hanoi

One Disc

Let's simplify the problem to clarify our thinking. Let's imagine the Towers of Hanoi problem with only one disc.

Figure %: Towers Problem with 1 Disc

How do we solve this problem? Simple. We just move the disc on the first pole to the third pole.