/* Egg basket puzzle in Picat. From Martin Chlond Integer Programming Puzzles: http://www.chlond.demon.co.uk/puzzles/puzzles1.html, puzzle nr. 3 Description : Egg basket puzzle Source : Boris Kordemsky - The Moscow Puzzles (P136) """ 3. A woman was carrying a basket of eggs to market when a passer-by bumped her. She dropped the basket and all the eggs broke. The passer-by, wishing to pay for her loss, asked, 'How many eggs were in your basket?' 'I don't remember exactly,' the woman replied, 'but I do recall that whether I divided the eggs by 2,3,4,5 or 6 there was always one egg left over. When I took the eggs out in groups of seven, I emptied the basket.' What is the least number of eggs that broke? (Kordemsky) """ This model was inspired by the XPress Mosel model created by Martin Chlond. http://www.chlond.demon.co.uk/puzzles/sol1s3.html This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import mip. main => go. go => MaxN = 6, X = new_list(MaxN), X :: 1..10000, N :: 1..10000, foreach(I in 1..MaxN) X[I] #> 0 end, N #> 1, % N = 2*X[1]+1, % N = 3*X[2]+1, % N = 4*X[3]+1, % N = 5*X[4]+1, % N = 6*X[5]+1, % N = 7*X[6] % generalized solution foreach(I in 1..MaxN) if I < MaxN then N #= (I+1)*X[I]+1 else N #= (I+1)*X[I] end end, % to see the infered domains % writeln(x_before=X), % writeln(n_before=N), solve($[min(N)], X), writeln(n=N), writeln(x=X), nl.