% N-queens problem by Ilkka Niemelä; % modified by Tomi Janhunen to place queens column-by-column % % q(t,X,Y) gives the legal positions of the queens % d(1..queens): facts for the dimension of the board. % Place a queen on each column using a choice rule 1 { q(X,Y):d(Y) } 1 :- d(X). % Make sure they don't threaten each other :- d(X), d(Y), d(X1), q(X,Y), q(X1,Y), X1 != X. :- d(X), d(Y), d(X1), d(Y1), q(X,Y), q(X1,Y1), X != X1, Y != Y1, abs(X - X1) == abs(Y - Y1). d(1..queens). % Typical command line % lparse -1 -d none -c queens=8 queens.lp | smodels