/* Global constraint atmost_nvalue in Picat. From Global Constraint Catalogue http://www.emn.fr/x-info/sdemasse/gccat/Catmost_nvalue.html """ The number of distinct values taken by the variables of the collection VARIABLES is less than or equal to NVAL. Example (4, <3, 1, 3, 1, 6>) The atmost_nvalue constraint holds since the collection <3, 1, 3, 1, 6> involves at most 4 distinct values (i.e., in fact 3 distinct values). """ 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 = 5, X = new_list(N), X :: 1..6, NVal :: 1..N, X = [3, 1, 3, 1, 6], atmost_nvalue(NVal, X), NVal = 4, Vars = X ++ [NVal], solve(Vars), println(x=X), println(nval=NVal), nl, fail, nl. go => true. atmost_nvalue(NVal, X) => nvalue(NVal2,X), NVal2 #=< NVal.