/* Challenging Logic Puzzle For 11 Year Olds (MindYourDecisions) in Picat. From MindYourDecisions "Challenging Logic Puzzle For 11 Year Olds" https://youtu.be/8EITLJf1nug """ Thanks to Pett for the suggestion! This is adapted from the Singapore International Math Olympiad Challenge (SIMOC) 2015 – Primary 5 Paper, problem 24. Avery and Bryan have the following conversation: Avery: I am thinking of two different one-digit numbers. Can you guess their sum? Bryan: No. Can you give me a clue? Avery: The last digit of their product is the same as your house number. Bryan: Let me work it out... Now I know! What is the sum of the two numbers? I think this is a challenging logic puzzle for adults, and I would be impressed if any 11 year olds could solve it! As usual, a suggested solution in a video/post. Video https://youtu.be/8EITLJf1nug """ unique = [1,9] [x = 3,y = 7,product_last_digit = 1,sum = 10] [x = 1,y = 9,product_last_digit = 9,sum = 10] This model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> [X,Y,P1,P2] :: 0..9, X #< Y, % symmetry breaking: needed for uniqueness. % The sum S #= X + Y, % The product, to get the last digit X*Y #= 10*P1 + P2, P2 #!= 0, % There can be no 0 as house number, right? % Get all solutions and figure out which product(s) that has % a unique last digit. All = solve_all([X,Y,S,P1,P2]), LastDigit = new_map(), foreach(A in All) Last = last(A), LastDigit.put(Last, LastDigit.get(Last,0)+1) end, % We have two digits that has a unique last digit: 1 and 9. % The sum is 10 for both. Unique = [D : D=A in LastDigit,A==1], println(unique=Unique), foreach(U in Unique) foreach(A in All) if last(A) == U then println([x=A[1],y=A[2],product_last_digit=U,sum=A[3]]) end end end, nl. go => true.