Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Tower of Hanoi Solution

The binary numbers, considered in numerical order, comprise a set of


sequential moves that will allow you to solve the game of the Tower of
Hanoi with the minimum number of moves, specifically
2n - 1
where n is the number of disks. Each binary number is read from the
right until the first "1" is encountered. The position of that "1" from the
right indicates the disk to move. If there is no other "1" in the binary
number, that disk is moved to an empty peg. The second "1" from the
right indicates the location of the reference disk. If there are no or an
even number of zeros between these two "1"s (the first two "1"s from the
right), the moving disk is moved so as to cover the reference disk. If
there is an odd number of zeros between these two "1"s, the moving disk
is moved so as NOT to cover the reference disk.
A few examples for five disks follow:
Move
8
13
25
18
10
17

Binary Number
01000
01011
11001
10010
11010
10001

Interpretation
Move disk 4 to empty peg.
Move disk 1 to cover disk 2.
Move disk 1 to cover disk 4.
Move disk 2 to cover disk 5.
Move disk 2 NOT to cover disk 4.
Move disk 1 NOT to cover disk 5.

The table below lists the 25- 1 = 31 sequential moves required for a tower
with five disks. Try it with the interactive tower in Towers of Hanoi
Puzzle. Before you begin, reset the number of blocks (disks) to five (5).
Move
1
2
3
4
5
6
7
8
9

Binary Number
00001
00010
00011
00100
00101
00110
00111
01000
01001

Interpretation
Move disk 1 to empty peg.
Move disk 2 to empty peg.
Move disk 1 to cover disk 2.
Move disk 3 to empty peg.
Move disk 1 NOT to cover disk 3.
Move disk 2 to cover disk 3.
Move disk 1 to cover disk 2.
Move disk 4 to empty peg.
Move disk 1 to cover disk 4.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

01010
01011
01100
01101
01110
01111
10000
10001
10010
10011
10100
10101
10110
10111
11000
11001
11010
11011
11100
11101
11110
11111

Move disk 2 NOT to cover disk 4.


Move disk 1 to cover disk 2.
Move disk 3 to cover disk 4.
Move disk 1 NOT to cover disk 3.
Move disk 2 to cover disk 3.
Move disk 1 to cover disk 2.
Move disk 5 to empty peg.
Move disk 1 NOT to cover disk 5.
Move disk 2 to cover disk 5.
Move disk 1 to cover disk 2.
Move disk 3 NOT to cover disk 5.
Move disk 1 NOT to cover disk 3.
Move disk 2 to cover disk 3.
Move disk 1 to cover disk 2.
Move disk 4 to cover disk 5.
Move disk 1 to cover disk 4.
Move disk 2 NOT to cover disk 4.
Move disk 1 to cover disk 2.
Move disk 3 to cover disk 4.
Move disk 1 NOT to cover disk 3.
Move disk 2 to cover disk 3.
Move disk 1 to cover disk 2.

You might also like