queens4(L) :-
    permutation([1,2,3,4], L),       
  check_diag_all(L).
  
check_diag_all([]).
check_diag_all([X|Xs]) :-
     constrain_between(X, Xs, 1),
     check_diag_all(Xs).

constrain_between(_X, [], _N).
constrain_between(X, [Y|Ys], N) :-
     no_attack(X, Y, N),
     constrain_between(X, Ys, N+1).

no_attack(X, Y, I) :-
  Xd1 is X+I,
  Xd1 \= Y,
  Xd2 is X-I,
  Xd2 \= Y.

  /*
  | ?- queens4(L).

L = [2,4,1,3] ? a

L = [3,1,4,2]

no

  */
  
