News for hackers. Stuff that matters.
Re:Show HN: Solving Sudoku using PHP. by jojo1 on Sunday March 27, 2011 @08:41AM (#2374845)
Maybe it's time to look at prolog. :-) P.s: Sorry for the broken new-lines.

:- use module(library(clpfd)). sudoku(Rs) :- flatten(Rs,Vs), Vs ins 1 .. 9, rows(Rs), columns(Rs), blocks(Rs), label(Vs), maplist(writeln,Rs).

rows(Rs) :- maplist(all distinct,Rs).

columns(Rs) :- columns(9,Rs). columns(0,Rs). columns(N,Rs) :- N > 0, N1 is N-1, maplist(nth0(N1),Rs,X), all distinct(X), columns(N1,Rs).

blocks([A,B,C,D,E,F,G,H,I]) :- blocks(A,B,C), blocks(D,E,F), blocks(G,H,I). blocks([],[],[]). blocks([A,B,C|Bs1],[D,E,F|Bs2],[G,H,I|Bs3]) :- all distinct([A,B,C,D,E,F,G,H,I]), blocks(Bs1,Bs2,Bs3).

Re:Show HN: Solving Sudoku using PHP. by JonnieCache on Sunday March 27, 2011 @08:54AM (#2374866)
To post code with newlines and whitespace preserved, prefix each line with four spaces.

http://news.ycombinator.com/formatdoc

Re:Show HN: Solving Sudoku using PHP. by jojo1 on Sunday March 27, 2011 @09:20AM (#2374910)
thx!
Re:Show HN: Solving Sudoku using PHP. by michael_dorfman on Sunday March 27, 2011 @08:51AM (#2374861)