Question: I want Python program to print all intermediate states based on algorithms i am providing: The Tower of Hanoi game consists of three rods and

I want Python program to print all intermediate states based on algorithms i am providing:
The Tower of Hanoi game consists of three rods and n disks of different sizes (denoted by 1,2,\ldots,n ) that can slide onto any rod. The initial state of the game consists of all the disks on one rod in ascending order, with disk 1, the smallest and lightest of the disks on top.
Each move in the game consists of choosing one rod, picking up the top disk from that rod, and placing it on another rod. Such a move is allowed only if the disk being moved is smaller than the top disk on the target rod, or if the target rod is empty.
If the three rods are placed on different points on a circle, at any given state, there are three possible moves:
0. Take disk "1" from its rod and move it clockwise to another rod.
1. Take disk "1" from its rod and move it counterclockwise to another rod.
2. Take a disk which is not "1" and move it to another rod.
Move 2 will not always be available, such as when all the disks are currently located on one rod. In such instances, we say that Move 2 does nothing. In all other cases, there is only one legal way to perform Move 2.
your Goal to write python program to print all intermediate states For the games defined by n=7 and moves="12021121120020211202121",
here we have three rods Let say A, B and C, Intially at rod A value is (1,2,3,4,5,6,7), and rod B value is empty('E'), and rod C value is also empty ('E'),
and after processing all moves based on given algorithm it will print all intermediate steps like provided in image:
output sequence should be like this
=(1234567,E,E)1,(234567,lon,1)2,(34567,2,1)0
(134567,2,E)2,(134567,lon,2)1,(34567,lon,12)1
(34567,1,2)2,(234567,1,E)1,(1234567,lon,E)1
(234567,E,1)2,(34567,2,1)0,(134567,2,lon)0
(34567,12,E)2,(4567,12,3)0,(4567,2,13)2,
(24567,E,13)1,(24567,1,3)1,(124567,lon,3)2
(124567,3,E)0,(24567,13,lon)2,(4567,13,2)1
(14567,3,2)2,(14567,23,E),(4567,23,1)1
for next iteration moves values are
Same i.e.12021121120020211202121
But input for rod A=4567,
B=23,
C=1,
NOTE: Here elon and E means empty value or you can say 0.
Write Python program to print all intermediates steps , here there are total 23 values in move so total intermediate steps are 23, it would be nice if you print step 1, step2,....step 23 like that.
I want Python program to print all intermediate

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!