Show HN: Solving Sudoku using PHP.
gist.github.com
Show HN: Solving Sudoku using PHP.
1–10 of 17 posts
Re: Show HN: Solving Sudoku using PHP.
#2Re: Show HN: Solving Sudoku using PHP.
#3:- 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.
#4If you'd like your code reviewed, post it on Stack Exchange Code Review[1]. [1] http://codereview.stackexchange.com/
Re: Show HN: Solving Sudoku using PHP.
#5Maybe 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]…
Re: Show HN: Solving Sudoku using PHP.
#6Maybe 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]…
Re: Show HN: Solving Sudoku using PHP.
#7Re: Show HN: Solving Sudoku using PHP.
#8I put the results on github a while back: http://github.com/AnthonySteele/SudokuSolver/blob/master/Sud...
IMHO the fact that it's fast and not very complex to brute-force Sudoku makes it a lot less interesting as a puzzle for people to solve.
Re: Show HN: Solving Sudoku using PHP.
#9Solving sudoku by brute force isn't much of a trick. Solving it using non-guessing techniques is the tricky bit.
Re: Show HN: Solving Sudoku using PHP.
#10Solving sudoku by brute force isn't much of a trick. Solving it using non-guessing techniques is the tricky bit.