Sudoku is a Japanese number/logic game I recently discovered on a flight from Cleveland to Salt Lake. The gentleman seated to my left was feverishly jotting down numbers in his book which contained a 9x9 grid of numbers and spaces. To satisfy my curiousity, I leaned over and asked him about it. Here's what he said:
There are just 3 rules to Sudoku:
Basic strategy
There are a number of ways to solve these puzzles. Here's one way: Basically, you go through each square and write down the list of possible values (given the constraints imposed by the columns and rows and 3x3 grid). You'll get something like this:
Then you go through and try to eliminate possibilities (trial and error, logic, etc.) until you've finished! Interested? There are four puzzles below, in increasing difficulty, for you to try out.
Oh, in case you're wondering, Sudoku is Japanese for "the digits must remain single"
Sudoku links:
Here's my pseudocode design for a Sudoku generator:
UPDATE: this code isn't very good. it will generate invalid boards that have the same numbers in a row or column. a better way would be to generate complete boards and remove numbers, the move numbers you remove the harder it will be
initialize 9 $smallBoards (3x3 grid)
initialize $largeBoard with those 9 $smallBoards
function ObtainCandidateValues ($largeBoard, $row, $column)
{
get possible (candidate) values from a $smallBoard
get candidate values from the $largeBoard row
get candidate values from the $largeBoard column
return $CVlist;
}
Main loop:
create a random list of reference to each of the 9 smallBoards
for each smallBoard in that list
{
if $difficulty_level==hard, pick a number from 0 to 5, set it equal to the variable $places
if $difficulty_level==medium, pick a number from 2 to 4, set it equal to the variable $places
if $difficulty_level==easy, pick a number from 3 to 5, set it equal to the variable $places
create a list $places random locations (inside a $smallBoard)
for each of those random locations
{
ObtainCandidateValues for that location
randomly choose a value from the list and assign it to the location
}
}
| 5 | 4 | 9 | 3 | |||||
| 9 | 1 | 2 | 7 | |||||
| 6 | 9 | 1 | 8 | |||||
| 8 | 9 | 6 | 2 | |||||
| 7 | 3 | 2 | 8 | |||||
| 4 | 1 | 6 | 9 | |||||
| 7 | 4 | 6 | 5 | |||||
| 2 | 3 | 8 | 1 | |||||
| 1 | 4 | 5 | 6 |
| 8 | 5 | 4 | 7 | |||||
| 8 | ||||||||
| 9 | 1 | 4 | 5 | 6 | ||||
| 3 | 7 | 9 | ||||||
| 7 | 1 | |||||||
| 1 | 3 | 7 | ||||||
| 9 | 2 | 8 | 5 | 3 | ||||
| 7 | ||||||||
| 7 | 8 | 2 | 1 |
| 4 | 9 | |||||||
| 1 | 2 | 4 | ||||||
| 8 | 3 | |||||||
| 6 | 9 | 8 | 1 | |||||
| 3 | 7 | 2 | 5 | |||||
| 2 | 3 | 9 | 4 | |||||
| 5 | 3 | |||||||
| 2 | 6 | 7 | ||||||
| 8 | 6 |
| 9 | 7 | 6 | ||||||
| 5 | 2 | |||||||
| 5 | 1 | 7 | ||||||
| 8 | 2 | 7 | ||||||
| 4 | ||||||||
| 6 | 7 | 4 | ||||||
| 3 | 6 | 9 | ||||||
| 1 | 4 | |||||||
| 8 | 5 | 2 |
|
| Web hosting by Utah Hub * Powered by CreativeTap * In association with Segomo |