1. Descriptions
a. Tower of Hanoi?
The Tower of Hanoi (also called the Tower of Brahma or Lucas’ Tower and sometimes pluralized as Towers) is a mathematical game or puzzle. It consists of three rods and a number of disks of different sizes, which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules.
b. Rules?
1. Only one disk can be moved at a time.
2. No disk can be placed on top of the smaller disk.
3. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.
2. How I sloved
Whatever happens, eventually I have to move the blocks from the left bar to the right bar. Therefore, the blocks (total blocks-1) are moved to the middle bar, the bottom block is moved to the right bar, and the blocks from the middle bar are moved to the right bar. I used a recursive to divide the number of blocks into one and more.
3. Code
def hanoitower(numOfBlock,a,b,c):
if (numOfBlock==1):
return blockList.append([a,c])
else:
hanoitower(numOfBlock-1,a,c,b)
blockList.append([a,c])
hanoitower(numOfBlock-1,b,a,c)
return blockList
input = int(input())
blockList = []
result = hanoitower(input,1,2,3)
print(len(result))
print(result)