/* The Item Cost Puzzle in Picat. Presh Talwalkar (MindYourDecisions): https://youtu.be/kQ_Nl-OH5oc """ A version of this problem appeared on the 1947 Stanford Competitive Examination. I bought 72 identical items. Each item had the same cost, and the cost was a whole number of dollars. The total cost was $_679_ (you do not know the first or last digit). How much did each item cost? """ total = 36792 cost = 511 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 = 72, TotalA = [_A,6,7,9,_E], TotalA :: 0..9, to_num(TotalA,10,Total), Cost * N #= Total, Vars = TotalA ++ [Total,Cost], solve(Vars), println(total=Total), println(cost=Cost), nl, fail, nl. go => true. % % converts a number Num to/from a list of integer List given a base Base % to_num(List, Base, Num) => Len = length(List), Num #= sum([List[I]*Base**(Len-I) : I in 1..Len]).