Blame view

code/asp/drafts/pqueens.lp 575 Bytes
3e0f9b8a   Francisco Coelho   back to work?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
% Column and row domains.
col(1 .. n).
row(1 .. n).
% One queen on some row per colum.
1 { queen(I, J) : row(J) } 1 :- col(I).
% One queen on some columns per row.
1 { queen(I, J) : col(I) } 1 :- row(J).
% Number descending diagonals.
diag1(I, J, I - J + n) :- col(I), row(J).
% Number ascending diagonals.
diag2(I, J, I + J - 1) :- col(I), row(J).
%
% Negative Restrictions
:- D = 1 .. 2 * n - 1, not { queen(I, J) : diag1(I, J, D) } 1.
:- D = 1 .. 2 * n - 1, not { queen(I, J) : diag2(I, J, D) } 1.
%
% Output this predicate.
#show queen/2.
%#show diag1/3.
%#show diag2/3.