Question: 1 . [ UP ] Turn an algorithm into a function ( Basic Programming ) - Bank 3 In this question, we want to test

1.[UP] Turn an algorithm into a function (Basic Programming)- Bank 3
In this question, we want to test your ability to implement an algorithm based on the pseudo-code we provide. For this purpose we will use the famous Tower of Hanoi 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 stacked 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:
1. Only one disk can be moved at a time.
2. 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.
3. No larger disk may be placed on top of a smaller disk.
With 3 disks, the puzzle can be solved in 7 moves. The minimal number of moves required to solve a Tower of Hanoi puzzle is 2"-1, where n is the number of disks.
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'moveTower' function below.
#
# The function accepts following parameters:
# 1. INTEGER height
# 2. STRING originalPole
# 3. STRING finalPole
# 4. STRING intermediatePole
#
def moveTower(height, originalPole, finalPole, intermediatePole):
# Write your code here
if __name__=='__main__':
height = int(input().strip())
originalPole = input()
finalPole = input()
intermediatePole = input()
moveTower(height, originalPole, finalPole, intermediatePole)
 1.[UP] Turn an algorithm into a function (Basic Programming)- Bank 3

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 Databases Questions!