/* Impossible house number and age puzzle in Picat. From MindYourDecisions """ This problem is from the 2016 International Championship of Mathematical Games. Benoît lives on a street where the houses are numbered consecutively from 1 to an integer greater than 2. Today he calculates the average of the other house numbers (every house except his own) and adds his age to this average. The result is the fractional number 20.16 (or 20 + 16/100). Today is Benoît’s birthday. What is Benoît’s age? """ [n = 26,house = 22,age = 7] This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. import mip. main => go. % Brute force go ?=> Mean = 20.16, % 20 + 16/100 Max = 100, member(N,3..Max), member(House, 1..N), member(Age,1..100), Houses = [I : I in 1..N, I != House], Mean == avg(Houses)+Age, println([n=N,house=House,age=Age]), nl. go => true. % For loop go2 => Mean = 20.16, Found = false, foreach(N in 3..100, House in 1..N, Age in 1..100, Houses = [I : I in 1..N, I != House], Mean == avg(Houses)+Age, break(Found==true)) println([n=N,house=House,age=Age]), Found := true end, nl. go3 => Mean = 20.16, println([ [n=N,house=House,age=Age] : N in 3..100, House in 1..N, Age in 1..100, Houses = [I : I in 1..N, I != House], Mean == avg(Houses)+Age]).