/* Global constraint product_ctr in Picat. From Global Constraint Catalogue http://www.emn.fr/x-info/sdemasse/gccat/Cproduct_ctr.html """ Constraint product_ctr(VARIABLES,CTR,VAR) Purpose Constraint the product of a set of domain variables. More precisely, let P denote the product of the variables of the VARIABLES collection. Enforce the following constraint to hold: P CTR VAR. Example (<2,1,4>,=,8) The product_ctr constraint holds since its last argument VAR=8 is equal (i.e., CTR is set to =) to 2*1*4. """ 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 = 3, Variables = new_list(N), Variables :: 1..4, Ctr = #=, TVar :: 0..1000, Variables = [2,1,4], % TVar #= 8, product_ctr(Variables, Ctr, TVar), Vars = Variables ++ [TVar], solve(Vars), println(variables=Variables), println(tvar=TVar), nl, fail, nl. go => true. product_ctr(Variables,Ctr,TVar) => Res #= prod(Variables), call(Ctr,Res,TVar).