tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
21
Task/N-queens-problem/Prolog/n-queens-problem-1.pro
Normal file
21
Task/N-queens-problem/Prolog/n-queens-problem-1.pro
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
solution([]).
|
||||
|
||||
solution([X/Y|Others]) :-
|
||||
solution(Others),
|
||||
member(Y, [1,2,3,4,5,6,7,8]),
|
||||
noattack(X/Y, Others).
|
||||
|
||||
noattack(_,[]).
|
||||
|
||||
noattack(X/Y,[X1/Y1|Others]) :-
|
||||
Y =\= Y1,
|
||||
Y1 - Y =\= X1 - X,
|
||||
Y1 - Y =\= X - X1,
|
||||
noattack(X/Y,Others).
|
||||
|
||||
member(Item,[Item|Rest]).
|
||||
|
||||
member(Item,[First|Rest]) :-
|
||||
member(Item,Rest).
|
||||
|
||||
template([1/Y1,2/Y2,3/Y3,4/Y4,5/Y5,6/Y6,7/Y7,8/Y8]).
|
||||
Loading…
Add table
Add a link
Reference in a new issue