/* Abbot's puzzle in Picat. From http://www.comp.nus.edu.sg/~henz/projects/puzzles/arith/index.html """ The Abbot's Puzzle from "Amusements in Mathematics, Dudeney", number 110. If 100 bushels of corn were distributed among 100 people in such a manner that each man received three bushels, each woman two, and each child half a bushel, how many men, women, and children were there? Dudeney added the condition that there are five times as many women as men. That way, the solution becomes unique (otherwise, there are seven solutions). """ Model created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => L = findall(LD, abbot(LD)), writeln(L), nl. % another approach go2 => L = findall(LD, abbot2(LD)), writeln(L), nl. abbot(LD) => LD = [M, W, C], LD :: 1..100, M + W + C #= 100, % Men: 3, Women: 2, Children: 1/2 = 100 M * 3 + W * 2 + C/2 #= 100, M * 5 #= W, % additional condition added by Dudeney solve([], LD). % Another approach abbot2(X) => N = 3, % Amount = [3.0, 2.0, 0.5], % float version Amount = [6, 4, 1], % multiply with 2 for the integer solution X = new_list(N), X :: 0..1000, scalar_product(Amount,X,200), sum(X) #= 100, X[2] #= 5*X[1], solve([], X).