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/library/gecode/clp_examples/queens.yap

22 lines
386 B
Plaintext
Raw Normal View History

2013-09-09 23:48:02 +01:00
:- use_module(library(maplist)).
:- [ge_clpfd].
queens(N, Queens) :-
length(Queens, N),
Queens ins 1..9,
all_distinct(Queens),
lconstrain( Queens, 0),
labeling([], Queens).
lconstrain([], _).
lconstrain( [Q|Queens], I0) :-
I is I0+1,
foldl(constrain(Q, I0), Queens, I, _),
lconstrain( Queens, I).
constrain(Q, I, R, J, J1) :-
J1 is J+1,
Q + I #\= R + J,
Q - I #\= R - J.