/* Lewis Carroll coin puzzle in Picat. From Martin Chlond Integer Programming Puzzles: http://www.chlond.demon.co.uk/puzzles/puzzles2.html, puzzle nr. 3. Description : Lewis Carroll coin puzzle Source : Wakeling, E., (1995), Rediscovered Lewis Carroll Puzzles, Dover. """ A man who possesses a half-sovereign, a florin and a sixpence goes into a shop and buys goods worth 7 shillings and 3 pence. But the shopkeeper cannot give him the correct change, as his coins are a crown, a shilling, and a penny. But a friend comes in the shop, and finds that he has a double-florin, a half-crown, a fourpenny piece and a threepenny bit. Can the shopkeeper effect an exchange that will enable him to give the man the correct change, and to give his friend the exact equivalent of his coins? (Wakeling) """ This model was inspired by the XPress Mosel model created by Martin Chlond. http://www.chlond.demon.co.uk/puzzles/sol2s3.html This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. import cp. main => go. go ?=> % buyer, shopkepper, friend Person = 3, Coin = 10, Requ = [63, 160, 85], Value = [120, 60,48,30,24,12,6,4,3,1], % decision variable X = new_array(Coin,Person), X :: 0..1, foreach(J in 1..Person) sum([Value[I]*X[I,J] : I in 1..Coin]) #= Requ[J] end, foreach(I in 1..Coin) sum([X[I,J] : J in 1..Person]) #= 1 end, solve(X), foreach(Row in X) println(Row.to_list()) end, nl, fail, nl. go => true.