/* Robinson's Age in Picat. From Adrian Groza "Modelling Puzzles in First Order Logic" """ Puzzle 9. Robinson’s age "How old are you, Robinson?” asked Colonel Crackham one morning. "Well, I forget exactly,” was the reply; "but my brother is two years older than me; my sister is four years older than him; my mother was twenty when I was born; and I was told yesterday that the average age of the four of us is thirty-nine years.” What was Robinson’s age? (puzzle 45 from Dudeney 2016) """ Unique solution: [robinson = 32,brother = 34,sister = 38,mother = 52] 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 ?=> [Robinson,Brother,Sister,Mother] :: 1..100, % "my brother is two years older than me;" Brother #= Robinson + 2, % "my sister is four years older than him;" Sister #= Brother + 4, % "my mother was twenty when I was born;" Mother #= Robinson + 20, % "and I was told yesterday that the average age of the four of us is thirty-nine years." 4*39 #= Robinson + Brother + Sister + Mother, % 39 #= (Robinson + Brother + Sister + Mother) div 4, % Gives the same solution Vars = [robinson=Robinson,brother=Brother,sister=Sister,mother=Mother], solve(Vars), println(Vars), fail, nl. go => true.