/* Enigma 737 - The Odd Dynasty in Picat. https://enigmaticcode.wordpress.com/2024/09/23/enigma-737-the-odd-dynasty """ Enigma 737: The odd dynasty From New Scientist #1892, 25th September 1993 I am nearly 100 years old and I have a son, grandson and greatgrandson, who were all born when their fathers were the same age. My greatgrandson loves numbers and has just noticed that each pair of our ages summed divides the product of our individual ages. What is the sum of our four ages? """ The unique solution: Ages: [14,42,70,98] Sum: 224 Nearly is here interepreted as between 90 and 99 years old. Note: if instead of "nearly 100 years old" it was "about 100 years old" then there are some other solutions: Ages: [42,63,84,105] Diff: 21 Sum: 294 Ages: [36,60,84,108] Diff: 24 Sum: 288 If "nearly 100 years old" would be interpreted as >= 80 years old: Ages: [12,36,60,84] Diff: 24 Sum: 192 Ages: [60,68,76,84] Diff: 8 Sum: 288 Ages: [40,56,72,88] Diff: 16 Sum: 256 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 ?=> nolog, N = 4, Ages = new_list(N), Ages :: 1..99, Ages[N] #>= 90, % Nearly 100 years old: between 90 and 99 Diff :: 1..100, foreach(I in 1..N-1) Diff #= Ages[I+1] - Ages[I] end, Product #= prod(Ages), foreach(I in 1..N, J in I+1..N) Product mod (Ages[I]+Ages[J]) #= 0 end, solve(Ages++[Diff,Product]), printf("Ages: %w Diff: %d Sum: %d\n", Ages, Diff, sum(Ages)), fail, nl. go => true.