Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need some help with PSEUDO CODE. The question is regarding a SUDOKU Puzzle. I need to create a function called MAKESOLUTION (row). Please read

I need some help with PSEUDO CODE. The question is regarding a SUDOKU Puzzle. I need to create a function called MAKESOLUTION (row). Please read the question and do not paste a copy and paste responds. Unfortunately, my question is getting spammed by someone who does not answer the question correctly

Please answer TASK 8 *******************************************************************************

Task 8: Complete the following function template: function MAKESOLUTION(row) end function This function will take the four-el Task 8: Complete the following function template: function MakeSolution(row) ... end function This function will take the four-element vector row as input, which is the same input for the function MakeVector. The function should return a solved Pseudoku puzzle such that all column and sub-grid Pseudoku conditions are satisfied. The function will generate a vector using MakeVector(row), then try cyclic permutations on this vector using PermuteRow(puzzle, x, y, z) until a set of permutations is found such that all Pseudoku conditions are satisfied (checked using CheckGrids and ColCheck). To be able to get full marks you should call the functions MakeVector, PermuteRow, CheckGrids and ColCheck. [6 marks] All of the methods above will just produce a solved Pseudoku puzzle. In order to produce a proper Pseudoku puzzle, numbers will need to be removed from the output of MakeSolution and replaced with a blank character. To complete the algorithm for generating Pseudoku puzzles, in addition to the input vector row, we have the integer n, which will stipulate the number of blank entries in the final puzzle.

BELOW PLEASE FIND HELPFUL INFORMATION TO SOLVE THE QUESTION: ********************************************************************************************

Background: Sudoku and Pseudoku A Sudoku puzzle consists of 9-by-9 grid of squares, some of them blank, some of them having integers from 1 to 9. A typical Sudoku puzzle will then look something like this: To solve this puzzle, all the squares must be filled with numbers from 1 to 9 such that the following are satisfied: 1. every row has all integers from 1 to 9 (with each appearing only once) 2. every column has all integers from 1 to 9 (with each appearing only once) 3. every 3-by-3 sub-grid, or block (with bold outlines around them going from top-left to bottom-right) has all integers from 1 to 9

Task 1: Complete the following function template: function MakeVector(row) new Vector puzzle(4) ... end function This function should take a four-element vector called row as an input parameter and return a vector of four elements called puzzle: each element of puzzle should contain the four-element vector row. Complete this function. [4 marks] Cyclic permutation of row vectors Consider the following vector: This does not satisfy the Pseudoku conditions since in each column only one number appears. The algorithm for generating Pseudoku puzzles will cyclically permute the elements in each row vector until the numbers in all the rows satisfy the Pseudoku conditions. A cyclic permutation of each row will shift all values of the elements one place to the left (or the right) with the value at the end going to the other end. For example, for the second element in the vector above, if we cyclically permute all elements one place to the left we will have: Given a four-element vector and an integer p between 0 and 3 (inclusive) we want to write a function to cyclically permute the values in the vector by p elements to the left. An elegant way to do this is to use the queue abstract data structure. All values in a vector will be enqueued to an empty queue from left to right, e.g. the vector above will give the following queue: To cyclically permute all values one place to the left we enqueue the value stored at the head, and then dequeue the queue. This process will then give the following queue: To cyclically permute the values we can just repeat multiple times this process of enqueueing the value at the head and then dequeueing. When we are finished with this process we then just copy (and overwrite) the values stored in the queue to our original vector and return this vector.

Task 2: Complete the following function template: function PermuteVector(row, p) if p = 0 then return row end if new Queue q ... end function This function should take a four-element vector called row as an input parameter and return that vector but with its values cyclically permuted by p elements to the left: p should be a number between 0 and 3 (inclusive). To be able to get full marks you need to use the queue abstract data structure appropriately as outlined above. [5 marks] The function PermuteVector, once completed, will only cyclically permute one vector. The next task is to take a vector puzzle of the form returned by the function MakeVector, and apply PermuteVector to each of the elements of puzzle. That is, given vector puzzle and three numbers x, y and z, elements 1, 2 and 3 of puzzle will be cyclically permuted x, y and z places to the left respectively.

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 MakeVector 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 system 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: 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].

Task 4: Complete the following function: function SearchStack(stack, item) ... end function This function will take a stack and a value (called item) as input parameters, and return FALSE if item is not stored in the stack, otherwise return the stack without the element storing item. [6 marks] To check whether a column contains all numbers from 1 to 4 in a puzzle vector, we will do the following: 1. Create a stack called numbers, which contains all numbers from 1 to 4 2. Initialise a variable k to be 1 3. For the element k in a column, store the number in that element to a variable called value and call SearchStack(numbers, value) 4. If the function returns FALSE, then we should return FALSE as a number appears twice or not at all in the stack 5. If the function returns the stack, increase the value of k by one and go to step 3 6. If after checking all elements in the column, SearchStack has not returned FALSE, we return TRUE In the next task you will need to complete a function that carries out this algorithm for column j of the input puzzle.

Task 5: Complete the following function: function CheckColumn(puzzle, j) ... end function This function will take the vector puzzle (as produced by MakeVector) as an input parameter and check that column j contains all numbers from 1 to 4: if it does contain all numbers from 1 to 4, it should return TRUE, otherwise it should return FALSE. The procedure you should use is the one outlined above. To get full marks you need to call SearchStack(stack, item). [4 marks] Once we have a method for checking one column, we can use the following function to check all columns: function ColChecks(puzzle) for 1 j 4 do if CheckColumn(puzzle, j) = FALSE then return FALSE end if end for return TRUE end function This will be useful later on. The next set of conditions to check is to see if all integers from 1 to 4 appear in the 2-by-2 sub-grids. In the next task, the goal is to replicate the approach of the function CheckColumn but for these sub-grids. In the function you should repeatedly call SearchStack for each element in a sub-grid, and then do this for all four sub-grids.

Task 6: Complete the following function: function CheckGrids(puzzle) ... end function This function will take the vector puzzle (as produced by MakeVector) as an input parameter and check that all sub-grids contain all numbers from 1 to 4: if every sub-grid does contain all numbers from 1 to 4, it should return TRUE, otherwise it should return FALSE. For each sub-grid you should create a stack with numbers from 1 to 4, and then repeatedly search the stack to see if the values in the sub-grid are stored there. To get full marks you need to call SearchStack(stack, item). [6 marks] Implementing the puzzle vectors A vector is an abstract data structure. When a vector just stores only a number in each element, we can straightforwardly implement the vector with an array where each element of the array stores a number. However, the vectors considered in this assignment store vectors in their elements. The next task in the assignment is to design a concrete data structure for implementing the puzzle vectors representing Pseudoku puzzles; importantly, each element of the concrete data structure can only store a number or a pointer. Therefore, you could try an implementation based on arrays or linked lists, or a hybrid of both.

Task 7: Consider the following puzzle vector: Design and explain a concrete data structure that implements this puzzle vector. The data structure must only consist of elements that can store an integer or a pointer to another element or null - elements can be indexed if they are contiguous in memory as with an array. You can draw the data structure and explain how the allowed operations of vectors are implemented on this concrete data structure - additional pointers can be created to traverse lists. One approach could be to use arrays, or linked lists, or another approach completely. [6 marks] This seventh task is intentionally vague to allow for all sorts of creative solutions, as long as they are well explained. Putting everything together We now have all the ingredients to generate a solved puzzle given a row vector called row. The next task will involve generating the initial four-element vector called puzzle from row using MakeVector(row), trying all cyclic permutations (using PermuteRow(puzzle, x, y, z) for all combinations of x, y and z) to see if the returned vector returns TRUE for both CheckGrids and ColChecks.

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_2

Step: 3

blur-text-image_3

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

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions

Question

Question Can a Roth IRA invest in stock of the IRA owners business?

Answered: 1 week ago

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago