/* Global constraint element_product in Picat. From Global Constraint Catalogue http://www.emn.fr/x-info/sdemasse/gccat/Celement_product.html """ Constraint element_product(Y, TABLE, X, Z) Purpose Z is equal to the Yth item of TABLE multiplied by X. Example (3,<6, 9, 2, 9>, 5, 10) The element_product constraint holds since its fourth argument Z=10 is equal to the 3th (Y=3) item of the collection <6, 9, 2, 9> multiplied by X=5. """ 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, ElementTable = new_list(N), ElementTable :: 1..9, X :: 0..10, Y :: 1..N, Z :: 0..100, ElementTable = [6,9,2,9], X #= 5, Y #= 3, element_product(Y,ElementTable,X,Z), Vars = ElementTable ++ [X,Y,Z], solve(Vars), println(elementTable=ElementTable), println([x=X,y=Y,z=Z]), nl, fail, nl. go => true. element_product(Y,ElementTable,X,Z) => element(Y,ElementTable,T), Z #= T * X.