/* Dividing the spoils puzzle in Picat. From Formula One samples: http://www.f1compiler.com/samples/Sam%20Loyd%27s%20Dividing%20The%20Spoils.f1.html """ Sam Loyd (1841-1911), America's most famous puzzle expert, presented the following problem: After gathering 770 chestnuts, the three little girls divided them up so that their amounts were in the same proportion as their ages. As often as Mary took four chestnuts, Nellie took three, and for every six that Mary received, Susie took seven. How many chestnuts did each girl get? """ 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 ?=> N = 770, Mary :: 0..N, Nellie :: 0..N, Susie :: 0..N, 3*Mary #= 4*Nellie, 7*Mary #= 6*Susie, Mary + Nellie + Susie #= N, Vars = [Mary,Nellie,Susie], solve(Vars), println([mary=Mary,nellie=Nellie,susie=Susie]), fail, nl. go => true. % % This works as well, i.e. no explicit domains, just #>= 0. % Though it's not recommended for larger problems. % The output shows the domains before and after constraints. % % just_larger_than_0 = [DV_027f8_0..72057594037927935,DV_02920_0..72057594037927935,DV_02a48_0..72057594037927935] % after_the_constraints = [DV_027f8_0..660,DV_02920_0..495,DV_02a48_0..770] % [mary = 264,nellie = 198,susie = 308] % go2 ?=> N = 770, Mary #>= 0, Nellie #>= 0, Susie #>= 0, println(just_larger_than_0=[Mary,Nellie,Susie]), 3*Mary #= 4*Nellie, 7*Mary #= 6*Susie, Mary + Nellie + Susie #= N, println(after_the_constraints=[Mary,Nellie,Susie]), Vars = [Mary,Nellie,Susie], solve(Vars), println([mary=Mary,nellie=Nellie,susie=Susie]), fail, nl. go2 => true.