Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating sudoku initial boards

Tags:

sudoku

Is there an algorithm or way I can get initial state sudoku puzzles for a sudoku game. Preferably with the ability to have different levels of difficulty?

like image 787
Devin Avatar asked Jul 10 '10 07:07

Devin


People also ask

What is the initial state of a Sudoku?

Initial State: A standard Sudoku board, with some of the boxes filled in as specified. Goal Test: A filled in Sudoku board with every row column and 3 × 3 grid having the digits 1-9. Successor Function: Fill a box with a number.


1 Answers

Basically there are two approaches. In both you need to have 2 solvers, a humanlike solver, which uses strategies performable by a human and a backtracking solver.

With the first approach you generate a random complete solution and iteratively remove random cells solutions. Backtracking solver will make sure, that there still exist only one solution, while the human-like solver will make sure, that its still solvable by human and it can be also used to measure the difficulty of the puzzle.

The second approach works in an opposite fashion. Firstly you create an empty board and place there randomly 17 cell solutions (in a consistent manner). 17 is the lowest filled cell count known to genrate a puzzle with unique solution. Now the algorithm in every step checks, if it has already an unique solution and if not, it adds another (consitently) filled cell. If the solution guarantees solution uniquesness and the puzzle is solvable by a human and the difficulty is below some limit, than the algorithm terminates.

like image 138
malejpavouk Avatar answered Oct 17 '22 21:10

malejpavouk