all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
26
Task/Sudoku/Prolog/sudoku.pro
Normal file
26
Task/Sudoku/Prolog/sudoku.pro
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
:- use_module(library(clpfd)).
|
||||
|
||||
sudoku(Rows) :-
|
||||
length(Rows, 9), maplist(length_(9), Rows),
|
||||
append(Rows, Vs), Vs ins 1..9,
|
||||
maplist(all_distinct, Rows),
|
||||
transpose(Rows, Columns), maplist(all_distinct, Columns),
|
||||
Rows = [A,B,C,D,E,F,G,H,I],
|
||||
blocks(A, B, C), blocks(D, E, F), blocks(G, H, I).
|
||||
|
||||
length_(L, Ls) :- length(Ls, L).
|
||||
|
||||
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).
|
||||
|
||||
problem(1, [[_,_,_,_,_,_,_,_,_],
|
||||
[_,_,_,_,_,3,_,8,5],
|
||||
[_,_,1,_,2,_,_,_,_],
|
||||
[_,_,_,5,_,7,_,_,_],
|
||||
[_,_,4,_,_,_,1,_,_],
|
||||
[_,9,_,_,_,_,_,_,_],
|
||||
[5,_,_,_,_,_,_,7,3],
|
||||
[_,_,2,_,1,_,_,_,_],
|
||||
[_,_,_,_,4,_,_,_,9]]).
|
||||
Loading…
Add table
Add a link
Reference in a new issue