% declarative solution, rather slow

%coordinates

numberList([1,2,3,4,5,6,7,8]).
letterList([a,b,c,d,e,f,g,h]).

% numbers corresponding to the letters

c(a,1).
c(b,2).
c(c,3).
c(d,4).
c(e,5).
c(f,6).
c(g,7).
c(h,8).

% initialize L and N, compute a combination and check whether it is consistent

queens(ResultList):-letterList(L),numberList(N),pos(L,N,ResultList),
                    consistent(ResultList).

% calculates the positions of the queens

pos([],[],[]).
pos(LList,NList,[[L,N]|PRest]):-member_del(LList,L,LRest),
                                member_del(NList,N,NRest),
                                pos(LRest,NRest,PRest).

% selects a member from the list and remove this element

member_del([L|R],L,R).
member_del([A|R],L,[A|R1]):-A\==L,member_del(R,L,R1).

% checks whether queens attack each other via comp

consistent([_|[]]).
consistent([E|L]):-L\==[],comp(E,L),consistent(L).

% calculating for one queen whether she attacks any of the others

comp(_,[]).
comp([L,N],[[L1,N1]|Rest]):-c(L,LN),c(L1,LN1),Z1 is LN-LN1,Z2 is N-N1,
                            abs(Z1,A1),abs(Z2,A2),A1\==A2,
                            comp([L,N],Rest).

