/* Family riddle (v 2) in Picat. From https://dmcommunity.org/challenge/challenge-june-2016/ """ Let’s assume that Rene and Leo are both heads of household, and, what a coincidence, both families include three girls and three boys. The youngest child in Leo’s family is a girl, and in Rene’s family, a little girl has just arrived. In other words, there is a girl in Rene’s family whose age is less than one year. Neither family includes any twins, nor any children closer in age than a year. All the children are under age ten. In each family, the sum of the ages of the girls is equal to the sum of the ages of the boys. The sum of the ages of all these children is 60. Question: What are the ages of the children in these two families? Send your solutions using any BR&DM tool (or none) to DecisionManagementCommunity@gmail.com. """ Note: There is a similar - but not identical - problem solved in http://hakank.org/picat/family_riddle.pi That problem has a unique solution, whereas the current problem has 266 solutions since the sum of squares constraint has been removed from the problem statement (see comment below). This model has also a variant of the concatenation of the lists. In the previous model we wrote % ... Leos = LeoBoys ++ LeoGirls, LeoGirls[1] #= min(Leos), % ... Here we do this instead, note the (....).vars construct: % ... ReneGirls[1] #= min((ReneBoys ++ ReneGirls).vars), % ... 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, ReneBoys = new_list(3), ReneBoys :: 0..9, ReneGirls = new_list(3), ReneGirls :: 0..9, Boys = LeoBoys ++ ReneBoys, Girls = LeoGirls ++ ReneGirls, all_different(LeoBoys ++ LeoGirls), all_different(ReneBoys ++ ReneGirls), % youngest is a girl ReneGirls[1] #= min((ReneBoys ++ ReneGirls).vars), LeoGirls[1] #= min((LeoBoys ++LeoGirls).vars), % rene has a newborn girl ReneGirls[1] #= 0, % sums sum(ReneBoys) #= sum(ReneGirls), sum(LeoBoys) #= sum(LeoGirls), %% sum of squares. %% Note: This was removed from the problem statement in %% in http://hakank.org/picat/family_riddle.pi % 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 children's ages is 60 sum((LeoBoys ++ LeoGirls ++ ReneBoys ++ ReneGirls).vars) #= 60, % symmetry breaking increasing(LeoBoys), increasing(LeoGirls), increasing(ReneBoys), increasing(ReneGirls), Vars = LeoBoys ++ LeoGirls ++ ReneBoys ++ ReneGirls, solve(Vars), println(leoBoys=LeoBoys), println(leoGirls=LeoGirls), println(reneBoys=ReneBoys), println(reneGirls=ReneGirls), nl, fail, nl. go => true.