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