Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

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: File I/O Review: CMPT 141 Readings Chapter 12 Note: A1Q4 asks about your work on A1Q3 Keep track of how long you spend working on this question, including time spent reading the ques- tion, reviewing notes and the course readings, implementing the solution, testing, and preparing to submit. Also keep track of how many times you experienced unscheduled interruptions, delays, or distractions during your work include things like social media, phone calls, texting, but not such things as breaking for a meal, exercise, commuting to or from the university. In A1Q4 you will be asked to summarize the time you spend working on A103. and your answer will be more helpful to you if you have more precise records. 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 | 12 | 3 4 5 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: 2011 3 4 5 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: | 2 3 7 0 4 8 1 5 6 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 . 'L i' means rotate row i to the left one position . 'U i' means rotate column i up one position 'D i' means rotate column i down one position. Here, i has to be a valid row or column index, that is: 0.12. Now that we have a code for the rotations, we can write sequences of rotations with this code. Suppose you are given an array A1 and and a sequence of unit rotations, for example (Note: this example was corrected 09/01/2020): 0 1 2 3 4 5 6 7 8 CN 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 314 8 67 0 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 a6 a7 28 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 read the file. perform the rotations, and display the array showing the effect of all the rota- tions done in the sequence given. For example, if the input file contains the following example (Note: this example was corrected 09/01/2020) 0 3 6 1 4 7 2 5 8 your program should read the file, perform the rotations, and finally display the result 1 2 5 3 4 8 6 7 0 Data files On Moodle you will find 2 ZIP files for your use in this question: a1q3Examples.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 Note: On 09/01/2020 these files were replaced, and new files were provided If you downloaded them before this date, discard those and download the new ones. 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. What to Hand In . Your implementation of the program: atq3.py . If you wrote a test script, hand that in too. calling it alq3_testing.py Evaluation . 10 marks: Your program works. 5 marks: Your program is well-documented

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

c. What groups were least represented? Why do you think this is so?

Answered: 1 week ago

Question

7. Describe phases of multicultural identity development.

Answered: 1 week ago