/* Global constraint all_min_dist in Picat. From Global Constraint Catalogue http://www.emn.fr/x-info/sdemasse/gccat/Call_min_dist.html """ Enforce for each pair (vari, varj) of distinct variables of the collection VARIABLES that |vari - varj| >= MINDIST. Example (2, <5, 1, 9, 3>) The all_min_dist constraint holds since the following expressions |5-1|, |5-9|, |5-3|, |1-9|, |1-3|, |9-3| are all greater than or equal to the first argument MINDIST = 2 of the all_min_dist constraint. """ Model created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => N = 4, X = new_list(N), X :: 1..9, C :: 0..9, % X = [5,1,9,3], C #= 2, L = findall([C,X], ( all_min_dist(C, X), Vars = X ++ C, solve([ffc],Vars) )), Len = length(L), foreach([C2,X2] in L) writeln([x=X2, c=C2]) end, writeln(len=Len). all_min_dist(_,[]) => true. all_min_dist(_,[_]) => true. all_min_dist(C, [H|Ts]) => foreach(T in Ts) abs(H-T) #>= C end, all_min_dist(C,Ts).