Fill the grid without clashes
After creating some interesting puzzles of my own design, I felt the site could do with a few classics that people would be familiar with.
I'd just finished adding Minesweeper and thought that a Sudoku puzzle would be another good addition.
To begin, I created a sudoku grid simulation with no UI, just a set of "Cell" objects that could be assigned to "Regions". These regions represent the rows, columns and boxes of the sudoku.
My first experiment was to try creating a valid finished sudoku, by starting with a completely random selection of digits, then going around fixing repeat digits until everything was fine.
This didn't work, because it was too dumb. A change to fix one repeated digit would cause another clash. The chances of it accidentally fixing everything was tiny and the script would run for minutes.
The solution wasn't actually too much work, it just had to be a little more clever. It still begins from a randomly filled grid, then looks forward to see what would happen if it fixed any one of the clashing digits. It finds the change that made the least problems, makes the change and repeats.
This means that it would keep making improvements until it removed every clash and the grid contained a solution.
Next, it needs to remove digits to find the starting state. The first version would pick a digit at random, remove it and then check that the grid still had only one solution
Using this, I could generate working sudoku puzzles. But it wasn't quite done.
The difficulty of a sudoku puzzle is only partially determined by how many digits are given.
More importantly is the complexity of the logical tricks required to solve them.
At this point it was getting quite complex, so I started using an AI assistant. Here's what I got it to create:
It built a sudoku solver that, instead of solving by trial and error, would use logical "tools" such as finding doubles, triples, x-wings, etc.
It would attempt to solve it with the most basic techniques and each time it failed, would add techniques until it could be solved. The more techniques it needed, the harder the puzzle.
As this is just a fun challenge and not intended for sudoku expert, I limited it to relatively straightforward techniques and made it reject puzzles that were too hard.
I hope that what I created here is a bit of a challenge, but is within the grasp of the average puzzle player.