July 24th, 2024

Generating sudokus for fun and no profit

Tom Nick created a free Sudoku application that generates puzzles based on human perception of difficulty, using advanced algorithms like CSP and Arc Consistency to improve solving efficiency and user experience.

Read original articleLink Icon
AppreciationEnjoymentCuriosity
Generating sudokus for fun and no profit

Tom Nick developed a free and open-source Sudoku application, sudoku.tn1ck.com, to provide a better experience for players, particularly his grandmother. The project involved creating a Sudoku generator that assesses difficulty based on human perception. The process begins with solving a Sudoku, which is essential for generating one. Various algorithms were explored, starting with a brute force method and advancing to more sophisticated techniques like Constraint Satisfaction Problems (CSP) and Arc Consistency.

The brute force approach, while simple, is inefficient. Improvements were made by implementing heuristics such as the Minimum Remaining Value, which selects cells with fewer possibilities, significantly reducing the number of iterations needed to solve difficult puzzles. The Arc Consistency method further refines the process by ensuring that the domains of variables (Sudoku cells) remain consistent with the constraints of the game.

To rate the difficulty of generated Sudokus, Nick utilized iteration counts from different solving strategies, comparing them to established difficulty levels from existing Sudoku databases. The analysis revealed a correlation between iteration counts and perceived difficulty, although it raised questions about the accuracy of these measures for human solvers.

The Sudoku generation process involves filling an empty grid with random numbers while ensuring uniqueness and solvability. The algorithm can adjust difficulty by adding or removing numbers, although generating highly difficult puzzles can be time-consuming due to the constraints involved. Overall, the project combines algorithmic innovation with a personal touch, aiming to enhance the Sudoku experience for users.

AI: What people are saying
The comments on Tom Nick's Sudoku application reflect a mix of appreciation and suggestions for improvement.
  • Users commend the application's user-friendly design and interactive features.
  • Several commenters share their experiences with other Sudoku games and generators, highlighting different approaches to puzzle difficulty.
  • There is interest in exploring advanced algorithms and techniques for generating and solving Sudoku puzzles.
  • Some users point out issues, such as broken links to resources and the desire for more puzzle variants.
  • Overall, the community expresses enthusiasm for the project and offers constructive feedback.
Link Icon 23 comments
By @Smaug123 - 9 months
Answering the object-level problem "my grandma wanted to play some sudokus on her computer", I really enjoyed the Cracking the Cryptic-affiliated game "Classic Sudoku", which is available on Steam, although some of the puzzles are really hard. The puzzles are all handmade, and many of them have some specific reason to exist: e.g. there's at least one which is clearly intended to teach you the swordfish pattern, and there are a few which appear to be built around some beautiful one-off ideas.
By @TN1ck - 9 months
Hi! I'm the author, didn't expect this to be posted here yet. I was still somewhat working on it, so please bear with me when you find anything weird. You can give me any feedback here.
By @lifebeyondfife - 9 months
The exponential number of symmetries present in sudoku problems, means that once you've found one valid instance, you've actually found up to 9! * 3!^4 * 8 which are exactly the same.

The numbers themselves are all interchangeable, so you have 9! combinations: 362,880.

Columns 1-to-3 are all interchangeable, as are 4-to-6, and 7-to-9. On top of this, these blocks of columns (1-to-3, 4-to-6, 7-to-9) are all interchangeable. Read about wreath products in group theory to know more. Each of the above symmetries are 3!, combined to yield 3! * 3! = 36 combinations. As well as the columns though, the rows have the same property, so those can be combined too: 36 * 36 = 1,296.

Finally, there are the symmetries of a square. Combining all rotations and flips yields a further 8.

In total, sudoku has 3,762,339,840 symmetries. Owing to the starting state of the sudoku puzzle being incomplete, the orbit of the set of points (more group theory) will be smaller than 3 billion, but it provides an efficient method of recreating many more puzzles with the same property. In this case, human complexity.

By @jmull - 9 months
I've found the best way to rate and generate puzzles of a certain perceived difficulty is to have a solver that works the way a human does.

So if you have a puzzle that can be solved using only techniques that interested people can come up with fairly readily/intuitively and apply without a lot of ceremony, then that would be, perhaps, very easy. The more advanced techniques (for humans) needed to solve the puzzle, the harder it would be rated.

You can also feed these techniques into the generation so that you can guide the difficulty as it's being generated (the way I did it, I found it would still fall into puzzles that are easier than the target, or get stuck on puzzles that are too hard, but applying adjustments to backtracking and forward progress based on heuristics observed in "stuck" scenarios seemed to do the trick.

By @thih9 - 9 months
I love the first sentence, peak hacking spirit.

> Once upon a time I decided to create a complete sudoku application as my grandma wanted to play some sudokus on her computer and I wasn't satisfied with the free offers available.

I liked the rest too and the website as well, especially the user friendly UX - the "applets" can be paused, the website has all kinds of display options, there are keyboard shortcuts and support for arrow keys.

My dream would be a "made for grandma" embeddable badge - and websites like this becoming a trend in 2024.

By @MontagFTB - 9 months
Generating Sudokus is a fond area of computing for me. Great job; the website is very thorough and readable.

Many years ago I wrote a Sudoku generator in C++ that was based on Knuth’s “dancing links” algorithm. It then analyzed the generated puzzle in terms of what techniques were necessary to solve it, and ranked them accordingly.

Perhaps there is still something useful in there: https://github.com/stlab/adobe_source_libraries/tree/main/te...

By @taeric - 9 months
Really fun visualizations. Well done!

I am a broken record on posts that mention sudoku in bringing in Knuth's treatment of it. He has a ton of really fun exercises on the game in the latest volume. Perhaps the most fun are the puzzles that have a single solution, but do not have enough information to place a single piece without ambiguity.

By @darkamaul - 9 months
Thanks a lot for your website - that was refreshing to see.

While I like the idea of using ARC3 to grade sudoku, I much prefer the approach developed by Andrew C. Stuart in [0], where they rely on the human techniques* needed to solve the sudoku. Indeed, Sudoku are small enough that a reasonable greedy algorithm is enough to solve them quasi instantly on modern hardware.

* techniques to solve the sudoku that can be applied by an human (as opposed to a computer).

[0]: https://www.sudokuwiki.org/Sudoku_Creation_and_Grading.pdf

By @dhosek - 9 months
There’s a part of me that still wants to tackle the question of calculating the number of possible Sudoko solutions (i.e., 9×9 grids that meet the constraints for a Sudoko) analytically rather than by brute force (which is how the number is currently calculated). Back in my grad school days (which also corresponded to the height of the Sudoko craze), I got a start on it, but got lost in the weeds pretty quickly. Maybe I should give it another try.
By @culi - 9 months
By @j7ake - 9 months
Visualising an algorithm with animations is so attractive for readers, kudos.
By @msg - 9 months
Simon Tatham's Portable Puzzle Collection has a Sudoku generator called Solo. On web, desktop, and mobile for free.

https://www.chiark.greenend.org.uk/~sgtatham/puzzles/js/solo...

By @lisper - 9 months
I highly recommend the Brainium sudoku app.

https://brainium.com/games/sudoku/

It has selectable difficulty and a "hint" mode that teaches you how to solve even the hardest sudokus without any backtracking search at all.

By @tpurves - 9 months
Coincidentally, while trying to get my daughter to sleep last night, I watched her solve a lengthy sudoko on my phone, while my own brain couldn't help to wander to imagining all the possible solver algorithms that might be out there. Or how I'd ever do in a technical interview if anyone asked me design one on the spot.

I got at least as far as thinking through something like your list of algorithms here. But I could help but imaging that there must also be even-more efficient or interestingly exotic solutions out there.

Like something amusing as a rainbow-table type approach where you calculate all the possible soduko boards in advance, then (somehow?) convert any given puzzle into just an index lookup of a matching solution. So like (perhaps a lot of) brute force up front, but O(1) in execution?

By @codetrotter - 9 months
In the article there is a link to one repo https://github.com/TN1ck/sudoku-analysis that returns 404 Not Found from GitHub. Maybe this repo is marked as private?
By @timonoko - 9 months
Learn Sudoku and Prolog in 8 minutes: https://youtu.be/5KUdEZTu06o?si=WOHkzN_xIT-7HoxZ
By @nanidin - 9 months
I remember the good old days when a bingo card generator was enough to sustain a lifestyle business
By @seb1204 - 9 months
I like this open source and privacy friendly app. https://github.com/SecUSo/privacy-friendly-sudoku
By @nevatiaritika - 9 months
I regularly enjoy competing with strangers on the livesudoku website: https://www.livesudoku.com/
By @chris_st - 9 months
If you like solving sudokus, and I'd be a bit surprised if you're here and don't :-), you might want try the app "Sumaddle" [1] available on (at least) iOS. It's a different kind of puzzle, but a very similar "get to a point where you can't figure out how to go forward, then realize there's a clever inference available" vibe.

1: https://apps.apple.com/us/app/sumaddle/id1552172214

By @the_arun - 9 months
I liked the simplicity of 'About' section of the blog. Nice way of presentation overall.
By @roshankhan28 - 9 months
never seen a blog which is that interactive. great work!