/* Dimes puzzle in Picat. http://brainyplanet.com/index.php/Dimes?PHPSESSID=051ae1e2b6df794a5a08fc7b5ecf8028 From rec.puzzles FAQ """ "Dad wants one-cent, two-cent, three-cent, five-cent, and ten-cent stamps. He said to get four each of two sorts and three each of the others, but I've forgotten which. He gave me exactly enough to buy them; just these dimes." How many stamps of each type does Dad want? A dime is worth ten cents. -- J.A.H. Hunter """ Note: The solution states one solution http://brainyplanet.com/index.php/Dimes%20Solution?PHPSESSID=051ae1e2b6df794a5a08fc7b5ecf8028 """ The easy way to solve this is to sell her three each, for 3x(1+2+3+5+10) = 63 cents. Two more stamps must be bought, and they must make seven cents (since 17 is too much), so the fourth stamps are a two and a five. """ I.e. the solution amount = [3, 4, 3, 4, 3] amount_gcc = [3, 2] cents = 70 But there is one other solution: amount = [3, 4, 3, 4, 4] amount_gcc = [2, 3] cents = 80 Note2: I've let values variable so we can study other things, say the maximum amount with "free" (ordered and distinct) values. There are 476 different solutions for values between 1..10. 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 ?=> Values = [1,2,3,5,10], dimes(Values, Amount,AmountGcc,Cents), println(amount=Amount), println(amountGcc=AmountGcc), println(cents=Cents), nl, fail, nl. go => true. dimes(Values, Amount,AmountGcc,Cents) => Values = new_list(5), Values :: 1..10, Amount = new_list(5), Amount :: 3..5, Cents :: 1..10000, all_different(Values), increasing(Values), Cents #= sum([Values[I]*Amount[I] : I in 1..5]), Cents mod 10 #= 0, % should be even dime AmountGcc = $[I-C : I in 3..4], global_cardinality(Amount,AmountGcc), Vars = Values ++ Amount ++ AmountGcc ++ [Cents], solve(Vars).