CSC1001: Introduction to Computer Science
Programming Methodology
Assignment 4
Assignment description:
This assignment will be worth 16% of the final grade. Please follow the template provided on Blackboard to write your code. Otherwise, you will get zero points.
You should write your code for each question in a .py file (please name it using the question name, e.g. for Question 1, name it q1.py). Please pack all your .py files into a single .zip file following the provided example 123456.zip on Blackboard, name it using your student ID (e.g. if your student ID is 123456, then the file should be named as 123456.zip), and then submit the .zip file via Blackboard.
Please also write a text file, which provide the details about how to run your code for each question. The text file should be included in the .zip file as well.
Please note that, the teaching assistant may ask you to explain the meaning of your program, to ensure that the codes are indeed written by yourself. We may check whether your program is too similar to your fellow students’ code using Blackboard.
Question 1 (20% of this assignment):
Question 2 (30% of this assignment):
Question 3 (50% of this assignment):
The Tower of Hanoi 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 following figure shows the initial state of the Tower of Hanoi with 5 disks.
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 i.e. a disk can only be moved if it is the uppermost disk on a stack.
3. No disk may be placed on top of a smaller disk.
Assume that initially all the disks are placed on rod A. Write a non-recursive Pythonfunction to print out the steps to move all the disks from rod A to rod C via rod B (Hint: a recursive algorithm can be converted into a non-recursive algorithm using stack). The header of the function is:
def HanoiTower(n)
Here n represents the number of disks. For example, when n = 3 the steps should be: