I've seen this article every now and then, and it's always fun to read. Something jumped out at me this time, though:
> As computer security expert Ben Laurie has stated, Sudoku is "a denial of service attack on human intellect". Several people I know (including my wife) were infected by the virus, and I thought maybe this would demonstrate that they didn't need to spend any more time on Sudoku.
Ah, yes... remember the halcyon days of 2006, when something as benign as Sudoku was considered to be a "denial of service attack on human intellect"?
It was a denial of service attack, not in the sense of soaking up my brain cells solving puzzles, but in causing me to devise and program my own solver. (In Java, text console only.) Once I wrote a solver, I felt as if I had solved all puzzles.
Then I got interested in devising puzzles with multiple solutions. Not too difficult. But making a few puzzles with two solutions was fun.
Then I got to looking at difficult puzzles on the web. Apparently AI escargot is the world's most difficult. (And the site http://www.aisudoku.com/index_en.html says I can't publish the board). So I'll only publish the stats of applying my solver to it.
Solution #1. Found in 0 days 00:00:00.029.
3,906 boards examined so far.
1 total solutions found.
7,832 total boards examined.
Total time 0 days 00:00:00.085.
Writing a sudoku solver/generator immediately and completely cured me of my crippling Sudoku addiction. I've been playing sudoku since I was probably 13, but after writing a solver I just can't muster up any interest to finish solving a puzzle. Not in a "my program could do this for me" sense, but more along the lines of "I've solved this and every other problem, now it's boring"
In that case, I have important news to tell you about! OpenAI has come out with am AI web browser! What is an AI web browser good for? I don't really know, but what you _can_ do, is log into hacker news with it, point it at your hacker news comment history, tell it to look at /newcomments page for stuff you'd want to comment on, and it'll shitpost for you!
What a wonderful time saver! Now you can get back to the important work of doing the dishes and folding laundry, and don't feel the need to personally participate in the denial of service attack on human intellect going on here.
> As computer security expert Ben Laurie has stated, Sudoku is "a denial of service attack on human intellect". […] I thought maybe this would demonstrate that [my wife doesn’t] need to spend any more time on Sudoku.
The same could be said about every logic puzzle, or other types of puzzles.
People don't do them so actually solve any sort of new problem, or achieve some sort of productivity.
The same reason people don’t jog to get from point A to point B, or to learn how to get around more quickly.
Logic puzzles are exercising parts of our brain that don’t get exercised regularly.
Most logic puzzles such as the software pack made from SGT (or under the paper puzzle booklets, same concept but with pens and paper) are trivially solvable with computers and often STEM people will get bored with them fast. Solve it once, solve it for all.
If any, the challenge and fun would come by solving them with an algorithm under its favourite programming language.
Also, lateral thinking based riddles/puzzles are often more fun to solve, such as the crime related ones.
Probably a joke... nevertheless I had the same reaction !
It exercises your deduction, binary thinking, also stochastic vs systematic methodology (first look around randomly find the most obvious before going number by number). Getting to discover all the tricks and reasoning in various "dimensions" is very satisfactory as well.
But above all sudokuing puts you in a sort of meditative state : focusing your mind on this micro deductive world gets rid of all the noise and can be very relaxing between 2 pomodoros :)
If you want to see a master craftsman, check out the fastest sudoku solver.
Uses constraint propagation, not any specialized sudoku solving algorithms. But this person is a CSP expert and finds ways to optimize CSP for sudoku in particular.
Then check out perhaps the worst sudoku solver, which works by translating the puzzle to a series of Python package requirements and then asking the package manager to resolve them: https://github.com/konstin/sudoku-in-python-packaging
That is an interesting post. However, a much more interesting challenge is solving larger Sudoku puzzles, as 9x9 is (as evidenced in the pos) a trivial problem to solve. 16x16 starts to get somewhat interesting, but at 25x25 it gets really interesting. Most solvers are trivially extensible to larger sizes, making it quite easy to benchmark.
In my testing, 25x25 Sudokus are algorithmically challenging. Solving times for a naive but well-tuned algorithm with reasonable heuristics can easily be on the order of an hour for a single puzzle. A smart system with advanced reasoning can be many orders of magnitude faster.
It does backtracking with recursion. It uses bitwise operations for fast conflict detection in rows, columns and 3x3 blocks. But one very important heuristics is that it firstly sorts the cells in such a way that the backtracking brute force starts from the most densely filled side. This eliminates a lot of wrong branches early, and actually helps a lot. I'm thinking maybe I can extend this to 16x16 or 25x25 as well. Not sure if this will scale up adequately. But this one usually cracks puzzles in a fraction of second. It only become slow for extremely hard killer sudoku puzzles.
You will most likely need both smarter heuristics and better deductions for larger instances. As mentioned, I've seen well-engineered custom tight C++-solvers with decent heuristics and the normal deductions take >1 hour on some instances. Most cases I've tried can be solved reasonably quickly when using OR-Tools CP-SAT which uses constraint programming style lazy clause generation to a SAT solver and custom MIP relaxations in a portfolio.
does not really do what you seem to intend. Sort requires a comparison function that is stable, and there are a lot of things that could go wrong if this is not supplied.
For shuffling, use a shuffle algorithm. Fisher-Yates is the common suggestion on what to use.
This is just for generation of sudoku image. The actual solver doesn't do this this expensive operation (the sudoku generator just reuses the solver function to fill with random numbers). From my experience for just generation it works good enough and fast enough. Yes I know how to efficiently shuffle by swaps in O(n) time with the correct distribution of probabilities (I didn't know that algorithm name BTW), I'm just too lazy =).
While Fisher-Yates or similar algorithms are more efficient, the real reason I wanted to mention it is that in many systems the sorting algorithm might crash or corrupt memory when used with a randomized comparison operator. It is inherently unsafe.
In JavaScript it's OK. At that time I knew that it is not the most efficient solution (for generation O(n log n) shuffle is not critical), just wanted to do this with simple one liner. With C++ I would definitely use this https://en.cppreference.com/w/cpp/algorithm/random_shuffle.h... .
The specification says that if the comparator is not a consistent comparator, the sort order is implementation defined: https://tc39.es/ecma262/multipage/indexed-collections.html#s... Further along, it is specified that only if the sort order is correct, are you guaranteed to get a permutation of the input as the result. I would not write code expecting this to work.
Thanks. I changed to a proper shuffling. Although there was nothing catastrophic in JS (like corruption, duplication / loss of elements), just more biased randomness and slower execution time (not critical for generation). But yeah, it was worth it for fair randomness.
I've seen this article every now and then, and it's always fun to read. Something jumped out at me this time, though:
> As computer security expert Ben Laurie has stated, Sudoku is "a denial of service attack on human intellect". Several people I know (including my wife) were infected by the virus, and I thought maybe this would demonstrate that they didn't need to spend any more time on Sudoku.
Ah, yes... remember the halcyon days of 2006, when something as benign as Sudoku was considered to be a "denial of service attack on human intellect"?
It was a denial of service attack, not in the sense of soaking up my brain cells solving puzzles, but in causing me to devise and program my own solver. (In Java, text console only.) Once I wrote a solver, I felt as if I had solved all puzzles.
Then I got interested in devising puzzles with multiple solutions. Not too difficult. But making a few puzzles with two solutions was fun.
Experiment_203(
// Solution #1. Found in 0 days 00:00:00.004.// 245 boards examined so far.
// Solution #2. Found in 0 days 00:00:00.001.// 287 boards examined so far.
Then I got to looking at difficult puzzles on the web. Apparently AI escargot is the world's most difficult. (And the site http://www.aisudoku.com/index_en.html says I can't publish the board). So I'll only publish the stats of applying my solver to it.Writing a sudoku solver/generator immediately and completely cured me of my crippling Sudoku addiction. I've been playing sudoku since I was probably 13, but after writing a solver I just can't muster up any interest to finish solving a puzzle. Not in a "my program could do this for me" sense, but more along the lines of "I've solved this and every other problem, now it's boring"
In that case, I have important news to tell you about! OpenAI has come out with am AI web browser! What is an AI web browser good for? I don't really know, but what you _can_ do, is log into hacker news with it, point it at your hacker news comment history, tell it to look at /newcomments page for stuff you'd want to comment on, and it'll shitpost for you!
What a wonderful time saver! Now you can get back to the important work of doing the dishes and folding laundry, and don't feel the need to personally participate in the denial of service attack on human intellect going on here.
> As computer security expert Ben Laurie has stated, Sudoku is "a denial of service attack on human intellect". […] I thought maybe this would demonstrate that [my wife doesn’t] need to spend any more time on Sudoku.
The same could be said about every logic puzzle, or other types of puzzles.
People don't do them so actually solve any sort of new problem, or achieve some sort of productivity.
The same reason people don’t jog to get from point A to point B, or to learn how to get around more quickly.
Logic puzzles are exercising parts of our brain that don’t get exercised regularly.
Feels like the "demonstrated it's no longer necessary to solve sudokus" statement may have been a joke :)
Most logic puzzles such as the software pack made from SGT (or under the paper puzzle booklets, same concept but with pens and paper) are trivially solvable with computers and often STEM people will get bored with them fast. Solve it once, solve it for all.
If any, the challenge and fun would come by solving them with an algorithm under its favourite programming language.
Also, lateral thinking based riddles/puzzles are often more fun to solve, such as the crime related ones.
Probably a joke... nevertheless I had the same reaction ! It exercises your deduction, binary thinking, also stochastic vs systematic methodology (first look around randomly find the most obvious before going number by number). Getting to discover all the tricks and reasoning in various "dimensions" is very satisfactory as well. But above all sudokuing puts you in a sort of meditative state : focusing your mind on this micro deductive world gets rid of all the noise and can be very relaxing between 2 pomodoros :)
>denial of service attack on human intellect
Sounds like social media feeds these days
Crossword puzzles were the big fad puzzle in the 1920s.
If you want to see a master craftsman, check out the fastest sudoku solver.
Uses constraint propagation, not any specialized sudoku solving algorithms. But this person is a CSP expert and finds ways to optimize CSP for sudoku in particular.
… And then does it all in SIMD.
https://t-dillon.github.io/tdoku/
Then check out perhaps the worst sudoku solver, which works by translating the puzzle to a series of Python package requirements and then asking the package manager to resolve them: https://github.com/konstin/sudoku-in-python-packaging
you know what the actual most interesting thint about this is for me?
this is the example that made me finally understand how to embed NO complete problems into other NP complete problems.
and this mofo wrote zero code yet tricked a programming language into doing work anyway
I will propose marriage to whoever wrote this: “you NP-complete me”
That's incredible and completely unhinged. I love it.
That is an interesting post. However, a much more interesting challenge is solving larger Sudoku puzzles, as 9x9 is (as evidenced in the pos) a trivial problem to solve. 16x16 starts to get somewhat interesting, but at 25x25 it gets really interesting. Most solvers are trivially extensible to larger sizes, making it quite easy to benchmark.
In my testing, 25x25 Sudokus are algorithmically challenging. Solving times for a naive but well-tuned algorithm with reasonable heuristics can easily be on the order of an hour for a single puzzle. A smart system with advanced reasoning can be many orders of magnitude faster.
Some time ago I wrote a 9x9 Killer Sudoku solver (you can solve ordinary as well, the cages are optional) in JavaScript https://github.com/surenenfiajyan/killer-sudoku-solver
It does backtracking with recursion. It uses bitwise operations for fast conflict detection in rows, columns and 3x3 blocks. But one very important heuristics is that it firstly sorts the cells in such a way that the backtracking brute force starts from the most densely filled side. This eliminates a lot of wrong branches early, and actually helps a lot. I'm thinking maybe I can extend this to 16x16 or 25x25 as well. Not sure if this will scale up adequately. But this one usually cracks puzzles in a fraction of second. It only become slow for extremely hard killer sudoku puzzles.
You will most likely need both smarter heuristics and better deductions for larger instances. As mentioned, I've seen well-engineered custom tight C++-solvers with decent heuristics and the normal deductions take >1 hour on some instances. Most cases I've tried can be solved reasonably quickly when using OR-Tools CP-SAT which uses constraint programming style lazy clause generation to a SAT solver and custom MIP relaxations in a portfolio.
For a list of interesting instances to test, see this file: https://github.com/Gecode/gecode/blob/release/6.3.0/examples...
I should probably do some benchmarks on that with the standard MiniZinc solvers.
Btw, note that the line
does not really do what you seem to intend. Sort requires a comparison function that is stable, and there are a lot of things that could go wrong if this is not supplied.For shuffling, use a shuffle algorithm. Fisher-Yates is the common suggestion on what to use.
This is just for generation of sudoku image. The actual solver doesn't do this this expensive operation (the sudoku generator just reuses the solver function to fill with random numbers). From my experience for just generation it works good enough and fast enough. Yes I know how to efficiently shuffle by swaps in O(n) time with the correct distribution of probabilities (I didn't know that algorithm name BTW), I'm just too lazy =).
While Fisher-Yates or similar algorithms are more efficient, the real reason I wanted to mention it is that in many systems the sorting algorithm might crash or corrupt memory when used with a randomized comparison operator. It is inherently unsafe.
In JavaScript it's OK. At that time I knew that it is not the most efficient solution (for generation O(n log n) shuffle is not critical), just wanted to do this with simple one liner. With C++ I would definitely use this https://en.cppreference.com/w/cpp/algorithm/random_shuffle.h... .
According to MDN it is expected to be an actual comparator: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
The specification says that if the comparator is not a consistent comparator, the sort order is implementation defined: https://tc39.es/ecma262/multipage/indexed-collections.html#s... Further along, it is specified that only if the sort order is correct, are you guaranteed to get a permutation of the input as the result. I would not write code expecting this to work.
Thanks. I changed to a proper shuffling. Although there was nothing catastrophic in JS (like corruption, duplication / loss of elements), just more biased randomness and slower execution time (not critical for generation). But yeah, it was worth it for fair randomness.
This guy under Common Lisp would shine.
I was a bit disappointed that he did not in fact solve all billions/trillons of possible sudoku puzzles.
You'd appreciate "Every 5x5 Nonogram": https://news.ycombinator.com/item?id=44140918
[dead]