Efficiently Generating Sudoku Puzzles by Difficulty

In summary, there may be a more efficient way to generate sudoku puzzles, but it still requires some optimization.
  • #1
Doom of Doom
86
0
I was wondering if there was a more efficient way of generating sudoku puzzles.

I already have a method to create puzzles of varying difficulties that goes something like this:
- Randomly generate a completed 9x9 solved sudoku
- Randomly remove some of the numbers from the matrix (as determined by the desired difficulty; more difficult means more are removed)
- Solve the puzzle using a logic method
- If more complex logic is needed to solve the puzzle, assign higher difficulty values
- If the final difficulty value is within the desired range, then the puzzle is good
- Else, start over.

This works, but is there a better way to more efficiently generate sudoku puzzles based on difficulty? I am trying to develop an algorithm that starts with an empty puzzle, then systematically fills in squares. The system in which it fills in squares should be different for varying levels of difficulty.
 
Technology news on Phys.org
  • #2
Seems like your first two steps could be replaced with these:

- Start with an empty Sudoku
- Add a few random numbers in such a way that keeps it consistent

The rest of the steps could then be followed as given.

- Warren
 
  • #3
You may underestimate the complexity of sudoku a bit.

Sure, it's simple to generate the solution, albeit there are many sudokus with higher complexity like X-soduku, disjoint group sudokus and disjoint group X-sudokus. That's much more fun.

But generating algoritms for the puzzle from that is not that simple. Certainly not at random. There are redundant numbers and key numbers. If you delete numbers at random you may have to stop at ~30 - 35 filled cells remaining to have a simple solution in basic soduku whereas selecting only key numbers this may reduce to some 22 filled cells. if you allow the higher solution techniques, like hidden and naked pairs (waiting for jesters) the number of filled cells may drop to 17-18 for the very advanced and still have a single solution.
 
  • #4
Finding a solution to a given variable sized sudoku is actually an NP-Complete problem so it's one of those computer-intractable problems.

Generating an instance of a k*k sudoku should be much much easier (not to say that it's easy or immediately obvious). You should be able to find libraries or code examples for generating sudoku games on the internet.
 

Related to Efficiently Generating Sudoku Puzzles by Difficulty

1. What is the purpose of generating Sudoku puzzles by difficulty?

The purpose of generating Sudoku puzzles by difficulty is to provide a range of puzzles that cater to different levels of players. This allows beginners to start with easier puzzles and gradually progress to more challenging ones, while also providing experienced players with a variety of challenging puzzles to solve.

2. How do you determine the difficulty level of a Sudoku puzzle?

The difficulty level of a Sudoku puzzle is determined by the techniques and strategies required to solve it. These techniques can range from basic logic and elimination to more advanced strategies such as X-wing and swordfish. The more advanced techniques required, the higher the difficulty level of the puzzle.

3. Can a computer efficiently generate Sudoku puzzles by difficulty?

Yes, a computer can efficiently generate Sudoku puzzles by difficulty using algorithms and techniques such as backtracking, constraint satisfaction, and genetic algorithms. These methods allow for the creation of puzzles with varying levels of difficulty while ensuring they have a unique solution.

4. How do you ensure that generated Sudoku puzzles have a unique solution?

To ensure that generated Sudoku puzzles have a unique solution, the algorithms used for puzzle generation must check for the uniqueness of the solution at each step. This means that the puzzle must have only one possible solution and that every move made during the solving process is unique.

5. Are there any benefits to generating Sudoku puzzles by difficulty?

Yes, there are several benefits to generating Sudoku puzzles by difficulty. It allows for a wider range of puzzles to cater to different skill levels, which can attract more players. It also helps players to improve their skills by gradually progressing to more challenging puzzles. Additionally, generating puzzles by difficulty can be used in educational settings to teach problem-solving and critical thinking skills.

Similar threads

  • Programming and Computer Science
2
Replies
37
Views
3K
  • Set Theory, Logic, Probability, Statistics
Replies
25
Views
3K
  • Programming and Computer Science
Replies
7
Views
12K
Replies
67
Views
5K
  • Programming and Computer Science
Replies
1
Views
667
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
Replies
1
Views
1K
  • Programming and Computer Science
Replies
19
Views
2K
  • Programming and Computer Science
Replies
29
Views
3K
Back
Top