First, run update21 to get the template files we have provided for you. These will serve as starting points for your programs. Next, use cd to change into your cs21/labs/06 directory and begin working on the Python programs for this lab. The pwd command helps you verify that you are in the correct sub-directory.
$ update21
$ cd cs21/labs/06
$ pwd
/home/your_user_name/cs21/labs/06
We will only grade files submitted by handin21 in this directory, so make sure your programs are in this directory!
For this lab assignment, you will write a single program that implements a famous puzzle called The Towers of Hanoi.

This puzzle consists of three rods along with a certain number of disks. Each disk has a diferent size. The disks on each rod are stacked, as shown in the picture. Disks can be moved from any rod to any rod, subject to the following rules:
Using the graphics library is NOT required, but is an optional extension.
Open the program hanoi.py and work incrementally towards implementing this puzzle.
In this lab, you should represent disks as integers 1,2,...,ndisks, where ndisks is the number of disks in the puzzle, and smaller numbers represent smaller disks. In addition to the disks, you should represent each rod as a list of positive integers, representing the disks that are on this rod. The integer at the end of the list represents the disk on top, while the disk at the beginning of the list represents the disk on the bottom of the rod.
Hint: how will you maintain this state? Recall that L[-1] returns the last element in a list.
Hint: Feel free to use any list method that you find in the Python documentation. In particular, the append and pop methods might be useful. append adds an element to a list. pop removes the last element from the list and returns the element. Sample code for these function calls lies below:
L = ["Jeff","Lisa"]
L.append("Joshua") # adds "Joshua" to end of list L
...
print(L.pop()) # removes "Joshua" from L, returns "Joshua"
For this lab, you will need to implement several helper functions which use lists, as well as a main program that calls the helper functions and implements functionality of the Towers of Hanoi puzzle. To help you out, we specify the functions you'll need to implement and some structure for incremental development below.
All of your functions should include a comment describing the behavior of the function, the parameters and the return value.
Note: do not delete your test() function. While in your final implementation, your main function should not call test(), we will look at this function to see how thoroughly you tested your helper functions.
>>> ndisks = getInt("How many disks do you want?", 1, 100)
How many disks do you want? -4
Please enter an integer between 1 and 100.
How many disks do you want? 101
Please enter an integer between 1 and 100.
How many disks do you want? 100
result = diskMovable(5, [], [5,4,3,2,1], []) # returns False result = diskMovable(5, [4,3], [2,1], [5]) # returns True
Note: when the user enters an invalid disk move, print an appropriate error message stating why the disk cannot be moved before prompting the user for another disk choice.
Once you have implemented and tested all of the helper functions listed above, you are ready to implement the main function. Your main function should do the following:
How many disks do you want? 3 Rod 1: [3, 2, 1] Rod 2: [] Rod 3: [] Game is not over! Which disk do you want to move? 1 Where do you want to move the disk? 3 Rod 1: [3, 2] Rod 2: [] Rod 3: [1] Game is not over! Which disk do you want to move? 2 Where do you want to move the disk? 3 I'm sorry, you can't place the disk here! Please try again. Where do you want to move the disk? 2 Rod 1: [3] Rod 2: [2] Rod 3: [1] Game is not over! Which disk do you want to move? 1 Where do you want to move the disk? 2 Rod 1: [3] Rod 2: [2, 1] Rod 3: [] Game is not over! Which disk do you want to move? 3 Where do you want to move the disk? 3 Rod 1: [] Rod 2: [2, 1] Rod 3: [3] Game is not over! Which disk do you want to move? 1 Where do you want to move the disk? 1 Rod 1: [1] Rod 2: [2] Rod 3: [3] Game is not over! Which disk do you want to move? 2 Where do you want to move the disk? 3 Rod 1: [1] Rod 2: [] Rod 3: [3, 2] Game is not over! Which disk do you want to move? 1 Where do you want to move the disk? 3 Rod 1: [] Rod 2: [] Rod 3: [3, 2, 1] You won!
Rod 1: [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4] Rod 2: [2, 1] Rod 3: [3] Which disk do you want to move? -1 quitting the game...
How many disks? 3 1 2 3 ------ 1 2 3 Which disk do you want to move? 1 Where do you want to move it? 3 2 3 1 ------ 1 2 3 Which disk do you want to move? 2 Where do you want to move it? 2 3 2 1 ------ 1 2 3
Remember you may run handin21 as many times as you like. Each time you run it new versions of your files will be submitted. Running handin21 after you finish a program, after any major changes are made, and at the end of the day (before you log out) is a good habit to get into.