/* A square family in Picat. From Adrian Groza "Modelling Puzzles in First Order Logic" """ Puzzle 11. A square family A man had nine children, as follows: 1. all born at regular intervals, and 2. the sum of the squares of their ages was equal to the square of his own. What was the age of each? Every age was an exact number of years. (puzzle 41 from Dudeney 2016) """ This model gives two (reasonable) solutions (i.e. with ages <= about 100) [x = [2,5,8,11,14,17,20,23,26],age = 48,dist = 3] [x = [4,10,16,22,28,34,40,46,52],age = 96,dist = 6] Groza only mentions the first one. 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 ?=> N = 9, Age :: 1..100, X = new_list(N), X :: 0..100, increasing(X ++ [Age]), Dist :: 1..10, foreach(I in 1..N-1) X[I]+Dist #= X[I+1] end, Age**2 #= sum([X[I]**2 : I in 1..N]), Vars = X ++ [Age,Dist], solve(Vars), println([x=X,age=Age,dist=Dist]), fail, nl. go => true.