<< sudoku_generate Generate sudoku_generate3 >>

Sudoku Toolbox >> Generate > sudoku_generate2

sudoku_generate2

Generate a puzzle and its solution.

Calling Sequence

[puzzle,solution] = sudoku_generate2 ( 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. 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 slow (typically 40 seconds).

Examples

sudoku_fillsingletons ( X )

Authors

<< sudoku_generate Generate sudoku_generate3 >>