/* Family riddle in Picat. From http://www.comp.rgu.ac.uk/staff/ha/ZCSP/additional_problems/family_riddle/family_riddle.pdf """ Rene and Leo are both heads of households with three boys and girls each. Neither family features any children closer in age than one year (i.e., no twins) and all children are under age ten. The youngest child in Leo’s family is a girl, and in Rene’s household a girl (aged zero) has just been born. In each family, the sum of the ages of the girls equals the sum of the ages of the boys. Likewise, the sums of the squared ages of the boys equals the sums of the squared ages of the girls. Summing the ages of all children yields 60 in both families. What are the ages of the children in each family? Table 1 shows the unique solution to this question. Leo Rene girls 3 7 8 0 5 7 boys 4 5 9 1 3 8 Table 1. Solution to the problem """ Also, see the Oz presentation and solution: http://www.mozart-oz.org/documentation/fdt/node22.html This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> LeoBoys = new_list(3), LeoBoys :: 0..9, LeoGirls = new_list(3),LeoGirls :: 0..9, Leos = LeoBoys ++ LeoGirls, ReneBoys = new_list(3), ReneBoys :: 0..9, ReneGirls = new_list(3), ReneGirls :: 0..9, Renes = ReneBoys ++ ReneGirls, Vars = Leos ++ Renes, % all different ages (in each family) all_different(Leos), all_different(Renes), % youngest is a girl ReneGirls[1] #= min(Renes), LeoGirls[1] #= min(Leos), % rene has a newborn girl ReneGirls[1] #= 0, % sums sum(ReneBoys) #= sum(ReneGirls), sum(LeoBoys) #= sum(LeoGirls), % sum of squares sum([ReneBoys[I]**2 : I in 1..3]) #= sum([ReneGirls[I]**2 : I in 1..3]), sum([LeoBoys[I]**2 : I in 1..3]) #= sum([LeoGirls[I]**2 : I in 1..3]), % sum of all is 60 sum(Vars) #= 60, % symmetry breaking increasing(LeoBoys), increasing(LeoGirls), increasing(ReneBoys), increasing(ReneGirls), solve(Vars), println(leo=[girls=LeoGirls,boys=LeoBoys]), println(rene=[girls=ReneGirls,boys=ReneBoys]), nl, fail, nl. go => true.