Page 1 of 1

Question 3 (20 points): Purpose: To build a program and test it, without starting with a design document. To get warmed

Posted: Fri May 20, 2022 5:03 pm
by answerhappygod
Question 3 20 Points Purpose To Build A Program And Test It Without Starting With A Design Document To Get Warmed 1
Question 3 20 Points Purpose To Build A Program And Test It Without Starting With A Design Document To Get Warmed 1 (85.01 KiB) Viewed 94 times
Question 3 20 Points Purpose To Build A Program And Test It Without Starting With A Design Document To Get Warmed 2
Question 3 20 Points Purpose To Build A Program And Test It Without Starting With A Design Document To Get Warmed 2 (81.69 KiB) Viewed 94 times
Question 3 20 Points Purpose To Build A Program And Test It Without Starting With A Design Document To Get Warmed 3
Question 3 20 Points Purpose To Build A Program And Test It Without Starting With A Design Document To Get Warmed 3 (103.95 KiB) Viewed 94 times
Question 3 20 Points Purpose To Build A Program And Test It Without Starting With A Design Document To Get Warmed 4
Question 3 20 Points Purpose To Build A Program And Test It Without Starting With A Design Document To Get Warmed 4 (41.44 KiB) Viewed 94 times
Question 3 20 Points Purpose To Build A Program And Test It Without Starting With A Design Document To Get Warmed 5
Question 3 20 Points Purpose To Build A Program And Test It Without Starting With A Design Document To Get Warmed 5 (51.16 KiB) Viewed 94 times
Question 3 20 Points Purpose To Build A Program And Test It Without Starting With A Design Document To Get Warmed 6
Question 3 20 Points Purpose To Build A Program And Test It Without Starting With A Design Document To Get Warmed 6 (60 KiB) Viewed 94 times
Question 3 (20 points): Purpose: To build a program and test it, without starting with a design document. To get warmed up with Python, in case you are using it for the first time. Degree of Difficulty: Moderate. Don't leave this to the last minute. This task involves an unfamiliar prob- lem, but the program itself is not more difficult than anything you've done in CMPT 141. References: You may wish to review the following chapters: • Lists: CMPT 145 Readings: Chapter 2. . File 1/0 Review: CMPT 141 Readings: Chapter 12 Restrictions: This question is homework assigned to students and will be graded. This question shall not be distributed to any person except by the instructors of CMPT 145. Solutions will be made available to students registered in CMPT 145 after the due date. There is no educational or pedagogical reason for tutors or experts outside the CMPT 145 instructional team to provide solutions to this question to a student registered in the course. Students who solicit such solutions are committing an act of Academic Misconduct, according to the University of Saskatchewan Policy on Academic Misconduct

The Torus Square The following description considers the manipulation of a 3 x 3 array of integers, which can be considered a kind of simple game. The description will start by describing the rules of the game, and then you'll be told what your task will be. It is highly unlikely that you will discover anything sensible on the internet about this game. It was invented by one of your instructors. Consider an 3 x 3 array of integers {0,-.,8} such as: 0 1 2 3 4 5 6 7 8 This is a kind of a puzzle, where we allow rows to be shifted left or right, and columns to be shifted up or down. We will call these actions unit rotations, for reasons that will be clarified immediately. A unit rotation is simply a shift of all the elements of a row (or column) by one position. For example, we can rotate the top row of the previous example one position to the right to get the following: 2 0 1 3 45 6 7 8 Notice that the integer 2 that was on the end of the row moved to the front after the rotation to the right Because the number 2 moved to the front of the row, we call it a rotation. Similarly, we can rotate the bottom row one position to the left to get the following: Page 7

1 20 3 4 5 7 86 Notice that the integer 6 that was on the front of the row moved to the end after the rotation to the left. Rotations of a row can be one position right, or one position left. Rotations of a column can be one position up, or one position down. When a column is rotated up the value on the top of the column is moved to the bottom of the column: all other elements are moved one place upwards. Because we only consider one position left, right up or down, we call it a unit rotation. When a row (or column) is rotated, only that row (or column) is rotated all other rows (or columns) remain unchanged. These unit rotations can be performed in sequences, one after another, which result in the numbers moving around the puzzle array. We will represent each possible rotation with a code, which we will motivate by example, and then define carefully after the example. A unit rotation of the first row to the right will be represented by the string 'R O'. The first letter 'R' indicates that a row is rotated to the right. The digit 'O' indicates that the first row is rotated. In general, a rotation will consist of a single letter followed by a single digit. . 'R i' means rotate row i to the right one position. . ' i' means rotate row i to the left one position. . 'U i' means rotate column i up one position. . ' i' means rotate column i down one position. Here, i has to be a valid row or column index, that is: 0. 1. 2. Now that we have a code for the rotations, we can write sequences of rotations with this code. Suppose you are given an array A, and and a sequence of unit rotations, for example:

The first three lines tell us the starting position. The number 2 tells us that there are two rotations to perform on the starting position. There are two rotations given (row o to the right, followed by column 2 up), which are the rotations used in the preceding description If we perform the given unit rotations, the resulting position would be the following: 1 2 5 3 4 8 6 7 o Task You'll be given several data files consisting of one example per file. Each file will describe an initial con- figuration of the puzzle, and then a sequence of unit rotations. In general, an example file will look like this:

a0 al a2 a3 a4 a5 a 6 a 7 a 8 N r1 IN The first three lines are the starting position of the puzzle array. Assume these will be numbers, in the range 0-8. The 4th line tells you the number of rotations to perform, and the remaining N lines describe each rotation (using the code above). Your job is to prompt the user for a filename, read the named file, perform the rotations, and display the array showing the effect of all the rotations done in the sequence given. For example, if the input file contains the following example: 0 1 2 | 3 4 5 6 7 8 2 L 0 U 2 your program should read the file, perform the rotations, and finally display the result: 1 2 5 3 48 6 7 0

Data files on Canvas you will find 2 ZIP files for your use in this question: • alq3Examples.zip Contains 15 example files with rotation sequences of different lengths. The file- names are torus_N_i.txt, where N tells you how long the rotation sequence is, and i is an index. There are 3 examples for each N. alq3Solutions.zip Contains 10 files that show the solutions for most of the examples. The solution file torus_N_i_solution.txt matches the example file torus_N_i.txt. We're not giving you solution files for all the examples, so that you have to be more thoughtful about assessing your work. You should be able to open ZIP files using software on any lab computer, and on your personal computer as well. If not, the ZIP format is standard, and File Compression utilities are easily downloaded from your favourite app store.