# Abella - Math031 M16 Algorithm and Validation of Tower of Hanoi

```Algorithm in Solving Tower Hanoi
Abella, Kean Adonis M. – Math031 M16
Rules:
1. Every move will be 1 disk at a time.
2. No larger disk over a smaller disk.
3. The whole set will be pegged at the 3rd pole.
Goals:
1. To transfer the whole tower to the third pole.
2. There will be 3 parts of process in solving:
(These 3 parts of process was observed in trying out the game: Go to validation based on playing the game, for more details)
Subgoals:
• First part is to isolate the largest disk in the first pole which also means that the
middle pole will be composed of the tower minus the largest disk.
• Second part is the transfer of the largest disk from the 1st pole to the 3rd pole.
• Third part is to place the tower in the 2nd pole to the 3rd pole.
Problem: How to solve Tower of Hanoi given with any number of disks.
Main Algorithm:
1. Identify if the number of disks is even or odd.
a. If odd, the first disk must be move to the 3rd pole.
b. If even, the first disk must be move to the 2nd pole.
2. Each disk must correspond to a number, either even or odd.
a. No odd disk must be placed on another odd disk.
b. No even disk must be placed on another even disk.
3. Move each disk legally.
4. At some point, there will be two places for a disk, either on an empty pole or non-empty pole,
place the disk on the non-empty pole but always mind number 2 algorithm.
5. Never move the same disk in succession.
There will always be another disk that can be moved every time a move is done if the rules and main
algorithm is being followed.
1
2
3
4
5
Identifying the number of disks and Corresponding each disk to a number.
Validation of the claim 𝟐𝒏 − 𝟏 steps to take before winning
Assuming:
𝑀𝑛 = number of moves
n = number of disks
n
𝑀𝑛
1
x = 2𝑛
Therefore,
When 𝑀𝑛+1
𝑀𝑛+1 = x
1
2
𝑀𝑛+1 = 2𝑛
2
3
4
𝑀𝑛 = 2𝑛 − 1
3
7
8
4
15
16
This is now the equation of the
5
31
32
minimum number of moves.
This generates a pattern of 2𝑛 .
Based on playing the game:
n
𝑀𝑛
1
1
2
3
3
7
3 (number of moves forming the middle tower) + 1 (Moving of the largest disk) + 3 (number of moves forming the final tower)
4
15
7 (number of moves forming the middle tower) + 1 (Moving of the largest disk) + 7 (number of moves forming the final tower)
this is 𝑀2
𝑀2 = total number of moves
when there are 2 disks.
this is 𝑀2
It was observed that there are 3 parts in solving the problem. Each part requires a certain
number of moves. It was noticed that before moving the largest disk to the third pole, it
generates a certain number of moves (1st part). In other words, in forming the tower in
the middle requires a certain number of moves. Turns out that in forming the final tower
after moving the largest disk to the third pole, generates the same number of moves.
1st Part (forming the tower in the middle)
𝑀3= 𝑀2+1+𝑀2
𝑀3= 2𝑀2+1
𝑀𝑛= 2𝑀𝑛−1+1
2nd part (moving of the largest disk to the 3 rd pole)
3rd part (forming the final tower)
1
```