/* Global constraint between_min_max in Picat. From Global Constraint Catalogue http://www.emn.fr/x-info/sdemasse/gccat/Cbetween_min_max.html """ VAR is greater than or equal to at least one variable of the collection VARIABLES and less than or equal to at least one variable of the collection VARIABLES. Example (3, <1,1,4,8) The between_min_max constraint holds since its first argument 3 is greater than or equal to the minimum value of the values of the collection <1,1, 4,8> and less than or equal to the maximum value of <1,1,4,8>. """ 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..8, NVar :: 1..8, X = [1,1,4,8], NVar #= 3, between_min_max(NVar, X), Vars = X ++ [NVar], solve(Vars), println(x=X), println(nvar=NVar), nl, fail, nl. go => true. between_min_max(NVar, X) => NVar #>= min(X), NVar #<= max(X)