queens(N,L) :-
   gen_list(N,1,L1),
   queens(L1,[],L).

gen_list(N,N,[N]) :- !.
gen_list(N,B,[B|T]) :-
   N1 is B + 1,
   gen_list(N,N1,T).

queens([],AllSafe,AllSafe).
queens(NotPlaced,Safe,Result) :-
   select(Queen,NotPlaced,RemainingNotPlaced),
   not_attack(Queen,Safe),
   queens(RemainingNotPlaced,[Queen|Safe],Result).


   

