Created
November 11, 2013 13:00
-
-
Save FeepingCreature/7412845 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module sudoku; | |
import std.util, std.coroutine, std.string, std.fun; | |
auto solve(string puz){ | |
alias s=string,v=void delegate(s); | |
void S(s p,v y){ | |
if (auto i=p.find"0"){p=p.dup;for int k<-0..9 if!sum$(0..81).select(λ(int j)->(i%9==j%9||i/9==j/9||i/27==j/27&&(i%9)/3==(j%9)/3)) | |
.map(λ(int i)->(p[i]=="1"+k)).eval{p[i]="123456789"[k];p.S y;}}else y p;} | |
return setupCoIterator!s new λ(v y)->puz.S y; | |
} | |
void main() { | |
string first <- cat("0" x 81).eval.solve(); | |
writeln first; | |
writeln "--"; | |
auto puz = "027800061000030008910005420500016030000970200070000096700000080006027000030480007"; | |
for string s <- puz.solve() writeln s; | |
} | |
--output-- | |
123456789456789123789123456214365897365897214897214365531642978642978531978531642 | |
-- | |
327894561465132978918765423589216734643978215172543896794651382856327149231489657 | |
327894561465132978918765423589216734643978215271543896794651382856327149132489657 | |
327894561645132978918765423589216734463978215172543896794651382856327149231489657 | |
327894561645132978918765423589216734463978215271543896794651382856327149132489657 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment