/* Yet another coin problem in Picat. From http://forum.openopt.org/viewtopic.php?id=5 """ In my pocket I have £41.58 which is made up of different denominations of coins. There is exactly the same number of each coin. What is the minimum number of coins I have, and what are they? (Britain has 8 commonly used coins, and in GBP their values are: 0.01, 0.02, 0.05, 0.10, 0.20, 0.50, 1, 2). """ 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 ?=> Denom = [1, 2, 5, 10, 20, 50, 100, 200], % in cents N = Denom.len, S = 4158, % 41.58 X = new_list(N), X :: 0..S, NumCoins #= sum(X), scalar_product(Denom,X,#=,S), all_same_except_0(X), solve($[min(NumCoins),degree,split],X), println(numCoins=NumCoins), println(x=X), nl. go => true. all_same_except_0(X) => N = X.len, foreach(I in 1..N, J in 1..N) X[I] #= X[J] #\/ X[I] #= 0 #\/ X[J] #= 0 end.