Blame view

code/asp/pqueens.lp 575 Bytes
808facfe   Francisco Coelho   Main text adapted...
1
2
3
4
5
6
7
8
9
10
11
% 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).
64dd7c8f   Francisco Coelho   Solved subset exp...
12
13
%
% Negative Restrictions
808facfe   Francisco Coelho   Main text adapted...
14
15
:- 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.
64dd7c8f   Francisco Coelho   Solved subset exp...
16
%
808facfe   Francisco Coelho   Main text adapted...
17
% Output this predicate.
1e848258   Francisco Coelho   Added biblio; Add...
18
#show queen/2.
64dd7c8f   Francisco Coelho   Solved subset exp...
19
20
%#show diag1/3.
%#show diag2/3.