111 points · by nu2ycombinator · 15y ago · 51 comments
Why did I do this? As computer security expert Ben Laurie
has stated, Sudoku is "a denial of service attack on human
intellect". My wife was infected by the virus, and I wanted
to convince her that the problem had been solved and didn't
need any more of her time.
Very true.The "Why?" at the end of the article pretty much sums up why I can't play most board games and puzzles. Once you 'solve' sudoku, chess, connect 6, ect. it really takes the fun out of it, even if your brain doesn't calculate the solution as quick as your code.
Sudoku Susser can solve sudoku puzzles not only the brute-force way shown in the article, but also using “human” reasoning, and show you all the steps.
He acknowledges the possibility of using more "reasoning" in the article, but dismisses it:
"We could try to code more sophisticated strategies. For example, the naked twins strategy looks for two squares in the same unit that both have the same two possible digits. [...] Coding up strategies like this is a possible route, but would require hundreds of lines of code (there are dozens of these strategies), and we'd never be sure if we could solve every puzzle."
If you want to read more about constraint programming, there is an excellent overview chapter in CTM (http://www.info.ucl.ac.be/~pvr/book.html). "The Art of the Propagator" (http://dspace.mit.edu/handle/1721.1/44215) is also good, though it focuses more on arithmetic value propagation than set propagation problems like sudoku. For more advanced material, look at the clp(FD) papers by Danial Diaz (http://cri-dist.univ-paris1.fr/diaz/publications/cv-short.ht...); familiarity with Prolog terminology will be helpful.
Growing up, we had a favorite game. That is until my sister solved it in that going first you could always win. It wasn't as fun after that.
Ours was a different game: Mühle. Also Mill or Nine Men's Morris.
I just discovered that Ralph Gasser solved it in 1996 using retrograde analysis and an 18-ply alpha- beta search. [1] Becoming "the first non-trivial game to be solved that does not seem to benefit from knowledge-based methods."
http://corp.galois.com/blog/2009/3/18/solving-sudoku-using-c...
It's a sudoku solver based on Cryptol, which is "... a language tailored for cryptographic algorithms." built on top of Haskell. The amazing this is that all you need to define is a function that checks whether a given board is solved. Cryptol does the searching for you!
For instance, I just rendered "In the Year 2525" 593 times faster than a human can listen to it on a single thread of a core i3.
https://github.com/biilmann/Ruby-DLX-Sudoku-Solver
It's not hyper-fast (for speed I actually implemented it as a c-extention to ruby, but it's a long time ago and I don't think I have the code around by now) but being ruby it's fairly easy to read.
Can really recommend reading the paper on Dancing Links and playing around with the algorithm, its such a great feeling once you start visualizing how the linked list trick works :)
http://www.amrittuladhar.com/projects/sudokusolver/
EDIT: Just realized the "load puzzle" feature doesn't seem to work on Chrome, but it does in other browsers.
In some cases you might want the algorithm that solves them to also give you some kinda hint on how hard it would be for a human to solve it.
The most efficient algorithm I know of to solve these kind of problems is Knuth's Dancing Links X algorithm. It's beautiful and very fun to implement.
I have a simple ruby implementation of it geared to solve sudokus online on github: https://github.com/biilmann/Ruby-DLX-Sudoku-Solver
I think the complexity class of Sudoko is NP-Complete (a quick google confirms it's not exactly NP but very close: http://11011110.livejournal.com/23221.html?thread=19381 -- complexity is the same as solving SAT problems which have only one unique solution)
I'd be very interested to see what an algorithm that solves any valid sudoku puzzle looks like. (apart from pathologic solutions like querying a database of all valid 9x9 sudoku combinations).
http://isaksky.wordpress.com/2010/10/30/objected-oriented-so...
"Did you know that in order to generate a sudoku you need first to solve it?"
another php version