Suduku
Suduku
The most common Sudoku puzzles use a 9 x 9 grid. The grids are partially filled,
requiring a minimum of 17 numbers, so that the player can reach a solution.
In the answer, each row and column (9 x 9) has the values between 1 and 9, and
each sub-grid (3 x 3) also contains the vlaues between 1 and 9.
Given a specific starting point of hints, there may be multiple correct answers to
the puzzle.
Alternate results:
Considerations:
if starting hint (3,3) value is 2 rather than 1 – infeasible solution
if hints (2,1) and (3,3) removed results in multiple solutions
Potential methods:
selectUnassignedLocation
usedInRow
usedInColumn
usedInSubGrid
validToPlace (calls usedInRow, usedInColumn,usedInSubGrid)
printGrid
Now that there is a Sudoku Solver how do you create the grid – use the solver!
Reuse!!!!!!
Creating the grid is based on 5 steps:
1. Generate a full grid of numbers (fully filled in). Cannot randomly generate
numbers to fill in the grid. Need to make sure that the numbers are
positioned on the grid following the Sudoku rules. To do so, use the sudoku
solver algorithm applied to an empty grid. Need to add a random element to
this solver algorithm to make sure that a new grid is generated every time it
is run.
2. From the completed full grid, remove 1 value at a time.
3. For each value removed, run the sudoku solver algorithm to see if the grid
can still be solved and to count the number of solutions it leads to.
4. If the resulting grid only has one solution, carry on the process from step 2. If
not need to put the value taken away back in the grid.
5. Repeat the same process from step 2 several times using a different value
each time to try to remove additional numbers, resulting in a more difficult
grid to solve. The maximum number of removals results in 17 numbers in the
partial grid.
Assignment:
You will work in a team of two to create the Sudoku Creater and Sudoku Solver.
Note that there will be two program templates for this assignment.
The Soduko Solver algorithm needs to be able to run as part of the Sudoku
Creator and independently. (Is there a way to create/use a common code
base?)
The output of the Sudoku Creator program is the input to the Sudoku Solver
program.
Assumptions:
Values entered will be integers
The format of the input is correct but not the values.
o That is, you still need to check that the values are between 1 and 9
0 will be treated as an invalid value
User will enter input and output file names
Program metrics:
You are to create metrics to see how efficient your program is – number of
comparisons to solve/create grid, how many backtracking actions take place. You
are to create three additional metrics.
Report:
You are to compare the metrics for multiple runs of your program – i.e. does the
difficulty of the puzzle (ratio of hints) match the ratio of backtacking actions.