% program predicate queen(X,Y) says that there is a queen in position (X,Y) % each row contains exactly one queen 1 { queen(X, Y) : number(Y) } 1 :- number(X). % each column contains exactly one queen 1 { queen(Y, X) : number(Y) } 1 :- number(X). % no two queens occur in the same diagonal :- number(X;X+I;I;Y), queen(X, Y), queen(X + I, Y + I). :- number(X;X+I;I;Y;Y-I), queen(X, Y), queen(X + I, Y - I). % the sum of the weights of blocks that have queens is at most w [ queen(X,Y) : number(X;Y) = weight(blockwt(X,Y)) ] w.