/* Price change puzzle in Picat. From Martin Chlond Integer Programming Puzzles: http://www.chlond.demon.co.uk/puzzles/puzzles4.html, puzzle nr. 8. Source: M Kraitchik, Mathematical Recreations (p 33-35), Dover This model was inspired by the AMPL model created by Martin Chlond. http://www.chlond.demon.co.uk/puzzles/sol4s8.html (Via the MiniZinc model http://hakank.org/minizinc/pchange.mzn) 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 ?=> M = 3, % dealers N = 2, % prices NSold = [10, 25, 30], % total number sold by each dealer % number sold by dealer i at price j X = new_array(M,N), X :: 0..max(NSold), % price j (i.e. first and second prices) P := new_list(N), P :: 1..10, foreach(I in 1..M, J in 1..N) X[I,J] :: 0.. NSold[I] end, foreach(I in 1..M) NSold[I] #= sum([X[I,J] : J in 1..N]) end, foreach(K in 2..M) sum([P[J] * X[1,J] : J in 1..N]) #= sum([P[J] * X[K,J] : J in 1..N]) end, P[2] #>= P[1]+1, Vars = X.vars ++ P, solve(Vars), println(p=P), foreach(Row in X) println(Row) end, nl, fail, nl. go => true.