0

My current plan is to generate an random initial board and randomly remove numbers. However, is there a way to make sure my puzzles are within a certain difficulty, like 'normal', without accidentally removing numbers so that the puzzle is too easy or hard?

Furthermore, do I have to include a simulated board solver to determine if a puzzle becomes unsolvable or too easy?

qwr
  • 9,525
  • 5
  • 58
  • 102
  • possible duplicate of [How to generate Sudoku boards with unique solutions](http://stackoverflow.com/questions/6924216/how-to-generate-sudoku-boards-with-unique-solutions) – Justin Ryder Jan 20 '14 at 22:02
  • @JustinRyder Once again, I am asking about a certain difficulty, not generating a unique solution. – qwr Jan 20 '14 at 22:19
  • Your first question is: How can I assign a 'difficulty' level to a Sudoku. This is probably Googleable and you should put it in your question. *Than* your question 'how do I generate a sudoka of difficulty X' makes sense. – Jan Doggen Mar 04 '14 at 19:38

3 Answers3

1

Difficulty typically refers to the amount of unnumbered spaces available at the start from what i've seen in sudoku. Why don't you start with a fully solved randomly created board, then from there start removing numbers, and starting from the most solved row/col/box to the least solved. Then you could have a variable to check to see if the removed spaces has reached the limit.

I would suggest basically starting with a solved world, a predecessor function that finds which row/col/box is the most solved i.e. has the most available correct numbers. And you can determine its meaning across the 3 different areas as you wish. Then a successor function that removes a space from the current row/col/box as well as updates each of those to reflect the update. Like say you have an int array for rows 0-8, another for cols 0-8, and box 0-8. Rows go from 0->8 from top to bot, cols 0->8 left to right, boxes 0->8 to the right then down a row and repeat. Start one off each with 9's in the indices. Each time you remove a number, say you remove (row#,col#). Then put row[row#]--, col[col#]-- and box[(row#/3)*3 + col#/3]--. Then increment a removed number counter and check that against your difficulty which is defied by total possible removed numbers. *Notice the (row#/3) is integer division.

Ion
  • 334
  • 3
  • 15
0

Randomly removing numbers will not guarantee there is ONE solution. This means it's unsolvable because SuDoKu in principle has only one solution per puzzle. Antyhing else, and we are thrown into a guess-and-check improv game that vaguely resembles the original. I definitely advise researching the puzzle you are trying to simulate and how to generate puzzles.

This question is a duplicate of How to generate Sudoku boards with unique solutions

Community
  • 1
  • 1
Chris Zhang
  • 968
  • 7
  • 16
  • I am asking about a certain difficulty. – qwr Jan 20 '14 at 21:16
  • 1
    In that case, use the links and research how to get the BARE minimum to guarantee one solution. This is the HARDEST difficulty. To make it easier, randomly choose other, non-essential positions and make those visible. To make it harder, show less. – Chris Zhang Jan 20 '14 at 21:18
  • That's not what he asked. If you remove up to 41 numbers, there's still a 50% chance that there is only one solution, so fewer recursions are needed to produce a valid puzzle. He is asking how one might control the difficulty of the puzzle by randomly removing numbers. – bryc Sep 17 '20 at 04:07
0

After doing some research, it turns out there's no easy way to accurately determine human difficulty, as described here. The easiest way is to count the number of blank squares.

However, some patterns are easier to find than others, such as if squares can be solved independently from others, or if there's only one solution available for a square. Difficulty and solving time require some statistical analysis of quite a few different patterns, and how many opportunities there are for strategies to be used.

qwr
  • 9,525
  • 5
  • 58
  • 102
  • That's why I suggest going from the most solvable row/col/square aka whichever is the most complete and removing and repeat. This will be solved independently for a bit, then eventually it will remove so much that the number in that square is based almost entirely on the numbers in squares that may not be filled in either – Ion Jan 21 '14 at 00:50
  • @Ion This is an interesting idea but sudoku solving patterns are not entirely based on how many squares there are for a row/col/box – qwr Jan 21 '14 at 03:38