Created
November 25, 2012 22:49
-
-
Save Mononofu/4145742 to your computer and use it in GitHub Desktop.
Straight-Forward sudoku solver
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
:- initialization(solve). | |
solve :- sudoku([_, _, 1, _, _, _, 8, _, _, | |
_, 7, _, 3, 1, _, _, 9, _, | |
3, _, _, _, 4, 5, _, _, 7, | |
_, 9, _, 7, _, _, 5, _, _, | |
_, 4, 2, _, 5, _, 1, 3, _, | |
_, _, 3, _, _, 9, _, 4, _, | |
2, _, _, 5, 7, _, _, _, 4, | |
_, 3, _, _, 9, 1, _, 6, _, | |
_, _, 4, _, _, _, 3, _, _], S), | |
print_sudoku(S). | |
print_sudoku([]). | |
print_sudoku([R1,R2,R3,R4,R5,R6,R7,R8,R9|B]) :- | |
format('~d ~d ~d | ~d ~d ~d | ~d ~d ~d \n',[R1,R2,R3,R4,R5,R6,R7,R8,R9]), | |
print_sudoku(B). | |
sudoku(Puzzle, Solution) :- | |
Solution = Puzzle, | |
Solution = [A1, A2, A3, A4, A5, A6, A7, A8, A9, | |
B1, B2, B3, B4, B5, B6, B7, B8, B9, | |
C1, C2, C3, C4, C5, C6, C7, C8, C9, | |
D1, D2, D3, D4, D5, D6, D7, D8, D9, | |
E1, E2, E3, E4, E5, E6, E7, E8, E9, | |
F1, F2, F3, F4, F5, F6, F7, F8, F9, | |
G1, G2, G3, G4, G5, G6, G7, G8, G9, | |
H1, H2, H3, H4, H5, H6, H7, H8, H9, | |
I1, I2, I3, I4, I5, I6, I7, I8, I9], | |
fd_domain(Puzzle, 1, 9), | |
fd_all_different([A1, A2, A3, A4, A5, A6, A7, A8, A9]), | |
fd_all_different([B1, B2, B3, B4, B5, B6, B7, B8, B9]), | |
fd_all_different([C1, C2, C3, C4, C5, C6, C7, C8, C9]), | |
fd_all_different([D1, D2, D3, D4, D5, D6, D7, D8, D9]), | |
fd_all_different([E1, E2, E3, E4, E5, E6, E7, E8, E9]), | |
fd_all_different([F1, F2, F3, F4, F5, F6, F7, F8, F9]), | |
fd_all_different([G1, G2, G3, G4, G5, G6, G7, G8, G9]), | |
fd_all_different([H1, H2, H3, H4, H5, H6, H7, H8, H9]), | |
fd_all_different([I1, I2, I3, I4, I5, I6, I7, I8, I9]), | |
fd_all_different([A1, B1, C1, D1, E1, F1, G1, H1, I1]), | |
fd_all_different([A2, B2, C2, D2, E2, F2, G2, H2, I2]), | |
fd_all_different([A3, B3, C3, D3, E3, F3, G3, H3, I3]), | |
fd_all_different([A4, B4, C4, D4, E4, F4, G4, H4, I4]), | |
fd_all_different([A5, B5, C5, D5, E5, F5, G5, H5, I5]), | |
fd_all_different([A6, B6, C6, D6, E6, F6, G6, H6, I6]), | |
fd_all_different([A7, B7, C7, D7, E7, F7, G7, H7, I7]), | |
fd_all_different([A8, B8, C8, D8, E8, F8, G8, H8, I8]), | |
fd_all_different([A9, B9, C9, D9, E9, F9, G9, H9, I9]), | |
fd_all_different([A1, A2, A3, B1, B2, B3, C1, C2, C3]), | |
fd_all_different([A4, A5, A6, B4, B5, B6, C4, C5, C6]), | |
fd_all_different([A7, A8, A9, B7, B8, B9, C7, C8, C9]), | |
fd_all_different([D1, D2, D3, E1, E2, E3, F1, F2, F3]), | |
fd_all_different([D4, D5, D6, E4, E5, E6, F4, F5, F6]), | |
fd_all_different([D7, D8, D9, E7, E8, E9, F7, F8, F9]), | |
fd_all_different([G1, G2, G3, H1, H2, H3, I1, I2, I3]), | |
fd_all_different([G4, G5, G6, H4, H5, H6, I4, I5, I6]), | |
fd_all_different([G7, G8, G9, H7, H8, H9, I7, I8, I9]), | |
fd_labeling(Solution). |
Ein tolles Buch, wenn ich es denn nur endlich einmal schaffen würde, weiter zu lesen ^^
Übrigens gibt es auch eine Seven Databases in Seven Weeks Version, die auch schon seit längerem ungelesen auf meinem Schreibtisch verschaubt. Die paar Ausschnitte, die ich beim Durchblättern gelesen habe, haben mich allerdings sehr neugierig gemacht. Wenn ich nur mehr Zeit zum Lesen hätte ^^
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
was sich so alles auf meiner platte findet xD