This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/CHR/chr/examples/examples-queens.domain

17 lines
303 B
Plaintext
Raw Normal View History

% n-queens with finite domains
:- setval(domain,number).
queen(N,L):-
length(L,N),
L::1..N,
queen(L).
queen([]).
queen([X|Xs]):- safe(X,Xs,1),queen(Xs).
safe(X,[],N).
safe(X,[H|T],N):- no_attack(X,H,N), M is N+1, safe(X,T,M).
no_attack(X,Y,N):- X ne Y, X ne Y-N, X ne Y+N, Y ne X-N, Y ne X+N.