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?
相关问题
- NetBeans IDE issue adding grid layout
- Java sudoku generator not working correctly
- Prolog predicate with variable number of arguments
- Brute force Algorithm for creation of Sudoku Board
- A cool algorithm to check a Sudoku field?
相关文章
- Prolog predicate with variable number of arguments
- Brute force Algorithm for creation of Sudoku Board
- A cool algorithm to check a Sudoku field?
- Help With Java Sudoku Permuter Program using Two D
- Dynamic generate sudoku board table using javascri
- Bash simplified sudoku
- Recursive solution to Sudoku generator
- How to generate Sudoku boards with unique solution
Had some fun with it in Scala. You can remove more cells to make it more difficult.Scala
A recursively way to get 9x9 sudoku elements.
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.
I believe Devin is looking for a initial sudoku configuration, or a sudoku puzzle (with less than 81 cells filled) which should guarantee 1 or more solution exists. A random N cell configuration may not guarantee a solution exists.
The way I think of is first obtain a full sudoku solution, using it as a base (name it X) X can be transformed into large amount of other valid sudoku solutions, X1, X2, X3, by applying any number of following transformations in any sequence: a. rotation b. mirror flip c. swap all number x with number y.
Each of these bases then can be used to generate your sudoku puzzle, by randomly deducting cells from the base.
You might be interested in this Sudoku generator.
I recently open sourced my Objective C Sudoku board generator, if you're interested...
http://jayfuerstenberg.com/devblog/open-source-code-for-developing-sudoku-for-iphone-and-os-x
It's obviously made for iPhone and the Mac but the logic is portable to whatever platform you happen to be developing for.