TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Solving Sudoku using PHP.

8 pointsby alienDeveloperabout 14 years ago

5 comments

beaumartinezabout 14 years ago
If you'd like your code reviewed, post it on Stack Exchange Code Review[1].<p>[1] <a href="http://codereview.stackexchange.com/" rel="nofollow">http://codereview.stackexchange.com/</a>
评论 #2374858 未加载
glenjaminabout 14 years ago
This is one of the best explanations on how to write an efficient brute-force sudoku solver with constraint propagation, it's in Python but should be perfectly readable.<p><a href="http://norvig.com/sudoku.html" rel="nofollow">http://norvig.com/sudoku.html</a>
评论 #2374919 未加载
jojo1about 14 years ago
Maybe it's time to look at prolog. :-) P.s: Sorry for the broken new-lines.<p>:- use module(library(clpfd)). sudoku(Rs) :- flatten(Rs,Vs), Vs ins 1 .. 9, rows(Rs), columns(Rs), blocks(Rs), label(Vs), maplist(writeln,Rs).<p>rows(Rs) :- maplist(all distinct,Rs).<p>columns(Rs) :- columns(9,Rs). columns(0,Rs). columns(N,Rs) :- N &#62; 0, N1 is N-1, maplist(nth0(N1),Rs,X), all distinct(X), columns(N1,Rs).<p>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).
评论 #2374866 未加载
评论 #2374861 未加载
StrawberryFrogabout 14 years ago
Though languages like Prolog and APL make brute-forcing suduko trivial, I'm pleased with how little code it took in c#<p>I put the results on github a while back: <a href="http://github.com/AnthonySteele/SudokuSolver/blob/master/SudokuSolver.cs" rel="nofollow">http://github.com/AnthonySteele/SudokuSolver/blob/master/Sud...</a><p>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.
wccrawfordabout 14 years ago
Solving sudoku by brute force isn't much of a trick. Solving it using non-guessing techniques is the tricky bit.
评论 #2374901 未加载
评论 #2374902 未加载