/* Honey division puzzle in Picat. From Martin Chlond Integer Programming Puzzles: http://www.chlond.demon.co.uk/puzzles/puzzles1.html, puzzle nr. 6. Description : Honey division puzzle Source : H E Dudeney - Amusements in Mathematics """ 6. Once upon a time there was an aged merchant of Baghdad who was much respected by all who knew him. He had three sons, and it was a rule of his life to treat them all exactly alike. Whenever one received a present, the other two were each given one of equal value. One day this worthy man fell sick and died, bequeathing all his possessions to his three sons in equal shares. The only difficulty that arose was over the stock of honey. There were exactly twenty-one barrels. The old man had left instructions that not only should every son receive an equal quantity of honey, but should receive exactly the same number of barrels, and that no honey should be transferred from barrel to barrel on account of the waste involved. Now, as seven of these barrels were full of honey, seven were half full, and seven were empty, this was found to be quite a puzzle, especially as each brother objected to taking more than four barrels of the same description - full, half full, or empty. Can you show how they succeeded in making a correct division of the property? (Dudeney) """ This model was inspired by the XPress Mosel model created by Martin Chlond. http://www.chlond.demon.co.uk/puzzles/sol1s6.html This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. import cp. main => go. go => Son = 3, Cap = 3, S = 1..Son, C = 1..Cap, % Howfull = [1, 0.5, 0] HowFull = [2, 1, 0], % multiplies with 2 for the integer version X = new_array(Son,Cap), X :: 1..4, SumX #= sum([X[I,J] : I in S, J in C]), % each son gets 7 barrels foreach(I in S) sum([X[I,J] : J in C]) #= 7 end, % each son gets 3.5 units foreach(I in S) % multiplies with 2 for the integer version sum([HowFull[J]*X[I,J] : J in C]) #= 7 end, % use 7 of each barrel capacity foreach(J in C) sum([X[I,J] : I in S]) #= 7 end, solve([ff], X.to_list() ++ [SumX]), writeln(sumX=SumX), foreach(Row in X) writeln(Row.to_list()) end, nl.