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- 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: 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
To complete Task 3 we need to write the function PERMUTERows in pseudocode This function will cyclic... View full answer
Get step-by-step solutions from verified subject matter experts
