/* Public School Problem in Picat. From Martin Chlond Integer Programming Puzzles: http://www.chlond.demon.co.uk/puzzles/puzzles2.html, puzzle nr. 6 Description : Public School Problem Source : Clarke, L.H., (1954), Fun with Figures, William Heinemann Ltd. """ At a public-school camp five schools, Aldhouse, Bedminster, Chartry, Radford and Rugenham were represented. The smallest contingent from the five schools was greater than 20 but less than 30. Aldhouse sent two less than half of the Rugenham contingent. The Radford and Rugenham contingents together were 14 greater than the combined Bedminster and Chartry contingents. The Bedminster and Rugenham contingents together were two short of half the total complement from the five schools while the Chartry and Radford contingents combined mustered 13/32 of that total. What was the strength of each contingent? (Clarke) """ This model was inspired by the XPress Mosel model created by Martin Chlond. http://www.chlond.demon.co.uk/puzzles/sol2s6.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 mip. main => go. go => N = 5, X = new_list(N), X :: 1..1000, M :: 21..29, foreach(I in 1..N) X[I] #>= M, X[I] #<= 1000 end, % integer version 2*X[1] #= X[5] - 4, % multiply by 2 X[4]+X[5] #= X[2] + X[3] + 14, 2*X[2]+2*X[5] #= sum(X) - 4, % multiply with 2 32*X[3]+32*X[4] #= 13*sum(X), % factor out the division solve(X ++ [M]), println(x=X), println(m=M), nl. % var float version: don't work go2 => N = 5, X = new_list(N), X :: 1..1000, M :: 21..29, foreach(I in 1..N) X[I] #>= M, X[I] #<= 1000 end, % float version X[1] #= 0.5 * X[5] - 2.0, X[4]+X[5] #= X[2] + X[3] + 14.0, X[2]+X[5] #= sum([0.5 * X[I] : I in 1..5]) - 2.0, T = 13.0/32.0, X[3]+X[4] #= sum([T * X[I] : I in 1..5]) , solve(X ++ [M]), println(x=X), println(m=M), nl.