/* Family ages in Picat. From Adrian Groza "Modelling Puzzles in First Order Logic" """ Puzzle 12. Family ages A man and his wife had three children, John, Ben, and Mary, and the difference between their parents' ages was the same as between John and Ben and between Ben and Mary. The ages of John and Ben, multiplied together, equalled the age of the father, and the ages of Ben and Mary multiplied together equalled the age of the mother. The combined ages of the family amounted to 90 years. What was the age of each person? (puzzle 37 from Dudeney 2016) """ Unique solution: [father = 36,mother = 36,john = 6,ben = 6,mary = 6] This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> % "A man and his wife had three children, John, Ben, and Mary," [Father,Mother,John,Ben,Mary] :: 1..100, % "and the difference between their parents’ ages was the same % as between John and Ben and between Ben and Mary." abs(Father-Mother) #= abs(John-Ben), abs(Father-Mother) #= abs(Ben-Mary), % "The ages of John and Ben, multiplied together, equalled the age of the father," John*Ben #= Father, % "and the ages of Ben and Mary multiplied together equalled the age of the mother." Ben*Mary #= Mother, % "The combined ages of the family amounted to 90 years." Father + Mother + John + Ben + Mary #= 90, Vars = [father=Father,mother=Mother,john=John,ben=Ben,mary=Mary], solve(Vars), println(Vars), fail, nl. go => true.