/* Global constraint alldiffrent_same_value in Picat. From Global Constraint Catalogue http://www.emn.fr/x-info/sdemasse/gccat/Calldifferent_same_value.html """ All the values assigned to the variables of the collection VARIABLES1 are pairwise distinct. NSAME is equal to number of constraints of the form VARIABLES1[i].var=VARIABLES2[i].var(1i|VARIABLES1|) that hold. Example ( 2, <7, 3, 1, 5>, <1, 3, 1, 7> ) The alldifferent_same_value constraint holds since: * All the values 7, 3, 1 and 3 are distinct, * Among the four expressions 7=1, 3=3, 1=1 and 5=7 exactly 2 conditions hold. """ This Picat model was 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..7, Y = new_list(N), Y :: 1..7, NSame :: 0..N, X = [7,3,1,5], % Y = [1,3,1,7], all_different_same_value(NSame, X,Y), NSame #= 2, Vars = X ++ Y ++ [NSame], solve(Vars), println(x=X), println(y=Y), println(nsame=NSame), nl, fail, nl. go => true. % % all_different_same_value % all_different_same_value(NSame, X, Y) => all_different(X), sum([X[I] #= Y[I] : I in 1..X.len]) #= NSame.