Prolog Constraint Programing finding even and odd numbers
问题 I need to create a predicate: applyConstraints(L) That applies constraints to the variables in L such that no two contiguous elements in L are both odd or even how can I do that? With a fixed size L it's simple but what about a variable size L? I need that to be done using sicstus-prolog clpfd library. 回答1: Inspired by @MatsCarlsson's version, I tried to minimize the number of constrained variables involved: applyConstraints(Xs) :- S #\= R, applyConstraints(Xs, S, R). applyConstraints([], _,