<< sudoku_generate2 Generate sudoku_rootsolution >>

Sudoku Toolbox >> Generate > sudoku_generate3

sudoku_generate3

Generate a puzzle and its solution.

Calling Sequence

[puzzle,solution] = sudoku_generate3 ( difficulty )

Parameters

difficulty:

the level of the puzzle, difficulty=1 is easy, difficulty=2 is medium, difficulty=3 is more difficult

puzzle:

the 9x9 puzzle matrix, with zeros for unknown entries

solution:

the 9x9 solution matrix without any zero

Description

Generates a random sudoku with sudoku_fillrandom. Then delete some entries according to the difficulty. Solves the puzzle and the transposed puzzle. If the two solutions are equal, the solution is probably unique: returns it. If not, continue to generate puzzles until unicity is achieved. This algorithm is less slow (typically less than 30 seconds).

Examples

sudoku_fillsingletons ( X )

Authors

Bibliography

"Enumerating possible Sudoku grids", Bertram Felgenhauer, Frazer Jarvis, June 2005


<< sudoku_generate2 Generate sudoku_rootsolution >>