%% representing the board %% using n as a constant col(1..n). % n column row(1..n). % n row %% generating the solution. 1 {cell(I,J) : row(J)} 1:- col(I). % each column one queen % two queens cannot be on the same row %:- col(I), row(J1), row(J2), neq(J1,J2), cell(I,J1), cell(I,J2). % two queens cannot be on the same column :- row(J), col(I1), col(I2), neq(I1,I2), cell(I1,J), cell(I2,J). % two quuens cannot be on a diagonal :- row(J1), row(J2), J1 > J2, col(I1), col(I2), I1 > I2, cell(I1,J1), cell(I2,J2), eq(I1 - I2, J1 - J2). :- row(J1), row(J2), J1 > J2, col(I1), col(I2), I1 < I2, cell(I1,J1), cell(I2,J2), eq(I2 - I1, J1 - J2). % hiding 'unneccessary' atoms hide row(_). hide col(_).