

Knuth on Sudoku - sublemonic
http://www-cs-faculty.stanford.edu/~uno/programs/sudoku.w

======
lpolovets
Trying to grok this. Seems like it's not producing a solution, but instead
producing a set of possible digits that can be put into each of the 81
squares. This output is then piped to Dance, which is presumably an
implementation of <http://en.wikipedia.org/wiki/Dancing_links> . Can someone
confirm?

I love the idea of transforming Sudoku to another problem that already has a
good solution instead of trying to attack it from scratch.

~~~
michael_dorfman
Sudoku is pretty clearly an "exact cover" problem, and there are loads of
known ways to attack those; Knuth's DLX being a particularly elegant one.

As a general principal, it's always a good idea to see if the problem you are
facing resembles other known, solved problems.

~~~
eru
Linear integer programming approaches also work well.

------
vl
There is also a wonderful article by Peter Norvig
<http://norvig.com/sudoku.html> with 100-line solver in Python.

~~~
icefox
The fact that it is in 100 lines really doesn't matter. The particular way
that python made his implementation small is interesting though.

------
nex3
Here's a PDF version, via Google Docs:
[https://docs.google.com/fileview?id=0B1njwImQ2AsFOGRjYmRmYWI...](https://docs.google.com/fileview?id=0B1njwImQ2AsFOGRjYmRmYWItMTJkMy00Yjc1LTkzMTgtNWRmOWJlMzY2YjM5&hl=en)

And a C version: <http://gist.github.com/319391>

~~~
apgwoz
> And a C version

I don't mean to be rude, or mean or anything, since you did take the time to
extract it and make a gist out of it, but you could have kept the formatting.

------
unwind
The comp.lang.c FAQ (which is quite well respected as a good authorative
source on C, I think) states:

Q: What's the correct declaration of main()?

A: There are two valid declarations:

    
    
        int main(void)
        int main(int argc, char **argv)
    

Yet, Knuth states:

    
    
        main()
    

This feels like Knuth has done a Chuck Norris on C.

~~~
jsharpe
Only problem - that ain't C. ;)

~~~
X-Istence
Oh? What language is it? At first glance it looked like C.

~~~
voidpointer
It's CWEB (<http://www-cs-faculty.stanford.edu/~uno/cweb.html>) A language
based on C devised by Knuth as a language for "Literate Programming"
(<http://www.literateprogramming.com/>)

------
s-phi-nl
For a tutorial on solving sudoku using Dancing Links, see this tutorial:
<http://cgi.cse.unsw.edu.au/~xche635/dlx_sodoku/>

------
snprbob86
I find this a bit hard to read. Can somebody render this CWEB(?) file to HTML
or PDF for the lazier of us?

------
habitue
That's so quaint that he uses the "register" storage class. Knuth is awesome

