move S disk to A or vice versa depending upon bigger of the two (i%3=2) 3. move S disk to D or vice versa depending upon bigger of the two (i%3=1) 2. If disk are odd or even (n%2 = 0) temp = D D = A A = temp //Basically interchanging Destination and Auxilaryįor (2 PW n)-1 times follow below these three steps 1. move D disk to A or vice versa depending upon bigger of the two (i%3=0) Repeat above steps till loop is completeĭry Run when disks are odd or even in number move A disk to D or vice versa depending upon bigger of the two (i%3=0) Repeat above steps till loop is complete if odd for (2 PW n)-1 times follow below these three steps 1. move S disk to D or vice versa depending upon bigger of the two (i%3=2) 3. move S disk to A or vice versa depending upon bigger of the two (i%3=1) 2. If disks are odd or even if even for (2 PW n)-1 times follow below these three steps 1. The minimal number of moves required to solve a Tower of Hanoi puzzle is 2 n − 1, where n is the number of disks. ![]() With 3 disks, the puzzle can be solved in 7 moves. ![]() ![]()
0 Comments
Leave a Reply. |