/* Global constraint alldifferent_modulo in Picat. From Global Constraint Catalogue http://www.emn.fr/x-info/sdemasse/gccat/Calldifferent_modulo.html """ Enforce all variables of the collection VARIABLES to have a distinct rest when divided by M. Example (<25, 1, 14, 3>, 5) The equivalence classes associated with values 25, 1, 14 and 3 are respectively equal to 25 mod 5 = 0, 1 mod 5 = 1, 14 mod 5 = 4 and 3 mod = 3. Since they are distinct the alldifferent_modulo constraint holds. """ 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..25, % X = [25,1,14,3], % M :: 1..5, % indomain(M), M = 5, % L = findall([X,M], $test(X,M)), L = findall([X,M], (alldifferent_modulo(X, M), solve(X++[M]))), Len = length(L), % this give no solution since the local X and M conflicts with the global versions % foreach([X,M] in L) writeln([m=M2,x=X2]) end, % this works, though foreach([X2,M2] in L) writeln([m=M2,x=X2]) end, writeln(len=Len). test(X,M) => alldifferent_modulo(X,M), solve(X). alldifferent_modulo(Xs,M) => all_different([T : X in Xs, T #= X mod M]).