Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Answer in Pseudo Code for Sudoku. Please answer Task 8. Complete function template: MAKESOLUTION. Below are the previous tasks as a reference only. Please DO

Answer in Pseudo Code for Sudoku. Please answer Task 8. Complete function template: MAKESOLUTION.

Below are the previous tasks as a reference only.

Please DO not complete MakeVector(row) that has been completed. Please help with Task 8.

image text in transcribed

The Question is based on the previous Tasks

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.

Task 3 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. 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.

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.

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).

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.

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).

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 MAKEVEC- TOR. 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

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

Oracle 11G SQL

Authors: Joan Casteel

2nd Edition

1133947360, 978-1133947363

More Books

Students also viewed these Databases questions

Question

Question What is a Roth 401(k) feature?

Answered: 1 week ago