Question: Task 3: Complete the following function template: function PERMUTERows(puzzle, x, y, z) end function This function should take a four-element vector called puzzle, which will

 Task 3: Complete the following function template: function PERMUTERows(puzzle, x, y,z) end function This function should take a four-element vector called puzzle,

which will be of the form of the output of MAKEVEC- TORas an input parameter, as well as three integers x, y and

Task 3: Complete the following function template: function PERMUTERows(puzzle, x, y, z) end function This function should take a four-element vector called puzzle, which will be of the form of the output of MAKEVEC- TOR as an input parameter, as well as three integers x, y and z. The function will return puzzle but with elements puzzle[1], puzzle[2] and puzzle[3] cyclically permuted by x, y and z elements respectively to the left: x, y and z should all be numbers between 0 and 3 (inclusive). To be able to get full marks you should call the function PERMUTEVECTOR appropriately. HINT: You do not need to loop over integers x, y and z. [3 marks] Checking the Pseudoku conditions The next step in constructing the algorithm is to write methods to decide if the Pseudoku conditions are satisfied. If we start with the output of the function MAKEVECTOR(row), then all of the row conditions are satisfied as long as row is a four-element vector with the numbers 1 to 4 only appearing once. However, the column conditions are not satisfied: only one number appears in each column (four times). The 2-by-2 sub-grid conditions are also not satisfied: in each sub-grid only two numbers appear (twice). We need a convenient way to refer to elements of the two-dimensional puzzle. We will use a coordinate sys- tem of (row,col) for the four-element vector puzzle as produced by MAKEVECTOR: row is the number of the element of puzzle that we care about, and col is the number of the element in puzzle[row] that we care about. Consider the following vector: Element1 2 3 Element 2 2 Element 3 2 Element 4 2 The coordinates of the element in yellow are (3,2), for example. So to select the value stored there we use the syntax puzzle[3][2], since we are looking at the second element in puzzle[3]. Using this coordinate system to re- fer to the 2-by-2 sub-grids, for example, the top-left sub-grid will consist of the elements (1,1), (1,2), (2.1) and (2,2). You will check the Pseudoku conditions using a stack. In particular, you will start with a stack containing all numbers from 1 to 4, and then inspect each element in each column (or sub-grid) to see if the number in that element is stored in the stack: if it is stored in the stack, pop that value from the stack and return the stack; otherwise, return false. This process will be repeated for every element in a column or sub-grid. If, at the end of checking every element, the stack is empty then all numbers appear in the the column or sub-grid; if the stack is not empty, then not all numbers from 1 to 4 appear. We will complete a function called SEARCHSTACK(stack, item) that will search a stack for the value item: if item is in one of the elements of the stack, we remove that element storing item. Otherwise, the function should return FALSE Let's demonstrate this with diagram. We have the following stack: 2 3 Top We want to look for the value 3 in the stack and remove it if it is there, otherwise if it is not there, return FALSE. The value 3 is stored in the stack so we then need to remove it so the stack could look like this: 2 Top The next task will be to complete a function that does this process of searching a stack and possibly removing an element Generating Pseudoku puzzles You are going to produce an algorithm that generates a Pseudoku puzzle. This algorithm starts with a vector of four elements, with all the integers 1 to 4 in any particular order, e.g. 1,2,3,4 or 4,1,3,2. In addition to this vector, the algorithm also starts with an integer n, which is going to be the number of blank spaces in the generated puzzle. This whole process will be more modular, i.e. the algorithm will combine multiple, smaller algorithms. The big picture of the algorithm is to construct a solved Pseudoku puzzle by duplicating the input vector mentioned earlier. Then from the solved puzzle, the algorithm will remove numbers and replace them with blank entries to give an unsolved puzzle. These are the main steps in the algorithm: 1. Get the input vector called row and number n 2. Create a vector of four elements called puzzle, where each element of puzzle is itself the vector row 3. Cyclically permute the elements in each element of puzzle so that puzzle satisfies the Pseudoku conditions 4. Remove elements in each element of puzzle to leave blank spaces, and complete the puzzle Steps 1 and 2 in this algorithm will involve writing functions in pseudocode and vector operations. Step 3 will, in addition to the tools in Steps 1 and 2, involve using queue operations and adapting the Linear Search algorithm. Step 4 can involve writing a function in pseudocode, or by some other means. In the following sections, there will be some introductory information to set out the problem that needs to be solved, along with the statement of task. The puzzle format As mentioned earlier, we will start with a completed puzzle stored in a four-element vector called puzzle where every element is itself a four-element vector, such as 2 41 3 1 3 2 4 3 2 4 1 4 1 3 2 Each row of the puzzle will correspond to an element of a vector, e.g. the first row of the Pseudoku puzzle will be stored as a four-element vector, which itself is an element of a four-element vector. Therefore, this completed Pseudoku puzzle is represented by the following vector: Element1 Element 2 Elements Element 4 We could make this vector by initiating a four-element vector, with each element being empty, and then assign a vector to each element. The goal of the algorithm in this coursework is to generate an unsolved Pseudoku puzzle from a row of four numbers. The first step in the process is to make all four elements of a four-element vector to be the same, and this element will be a four-element vector. For example, given a four-element vector with the numbers 2, 4, 1, 3, we produce the following vector: Element1 Element 2 Element 3 Element 3 Your first task is to write a function in pseudocode that will carry out this process

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To complete the function PERMUTERows you need to cyclically permute elements of a fourelement vector ... View full answer

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!