/* Global constraint among_modulo in Picat. From Global Constraint Catalogue http://www.emn.fr/x-info/sdemasse/gccat/Camong_modulo.html """ NVAR is the number of variables of the collection VARIABLES taking a value that is congruent to REMAINDER modulo QUOTIENT. Example (3, <4, 5, 8, 4, 1>, 0, 2) In this example REMAINDER = 0 and QUOTIENT = 2 specifies that we count the number of even values taken by the different variables. As a consequence the among_modulo constraint holds since exactly 3 values of the collection <4, 5, 8, 4, 1> are even. """ 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 ?=> X = new_list(5), X :: 1..8, NVar :: 0..10, Remainder :: 0..10, Quotient :: 1..10, X = [4,5,8,4,1], Quotient #= 2, Remainder #= 0, % NVar #= 3, among_modulo(NVar, X, Remainder, Quotient), Vars = X ++ [NVar,Remainder,Quotient], solve(Vars), println(x=X), println(nvar=NVar), println(quotient=Quotient), println(remainder=Remainder), nl, fail, nl. go => true. % % among_modulo % among_modulo(NVar, X, Remainder, Quotient) => NVar #= sum([X[I] mod Quotient #= Remainder : I in 1..X.len]).