<< sudoku_fillrandom Generate sudoku_generate2 >>

Sudoku Toolbox >> Generate > sudoku_generate

sudoku_generate

Generate a puzzle and its solution.

Calling Sequence

[puzzle,solution] = sudoku_generate ( difficulty )
[puzzle,solution] = sudoku_generate ( difficulty , verbose )

Parameters

difficulty:

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

verbose:

a boolean. Set to %t to display the state of the matrix. (default = %f)

puzzle:

the 9x9 puzzle matrix, with zeros for unknown entries

solution:

the 9x9 solution matrix without any zero

Description

Generates a puzzle and its solution based on the difficulty level.

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

This algorithm is limited in the sense that the difficulty is implied by the number of givens. Easy : unknowns from 40 to 45 (i.e. from 36 to 41 givens) Medium : unknowns from 46 to 49 (i.e. from 32 to 35 givens) Difficult : unknowns from 50 to 53 (i.e. from 28 to 31 givens) Extremely difficult: unknowns from 54 to 58 (i.e. from 27 to 23 givens) There is no real link between the number of unknowns and the actual difficulty of a sudoky puzzle. Therefore, this procedure is of limited usefulness.

The puzzle created by this algorithm is not symetric.

Examples

[puzzle,solution] = sudoku_generate ( 1 )

Authors

Bibliography

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

<< sudoku_fillrandom Generate sudoku_generate2 >>