/*
Dudeney's tea mixing problem in Picat.
From Martin Chlond Integer Programming Puzzles:
http://www.chlond.demon.co.uk/puzzles/puzzles2.html, puzzle nr. 4.
Description : Dudeney's tea mixing problem
Source : Dudeney, H.E., (1917), Amusements in Mathematics, Thomas Nelson and Sons.
"""
"Mrs Spooner called this morning," said the honest grocer to his assistant. "She wants twenty pounds of
tea at 2s. 4 1/2d. per lb. Of course we have a good tea 2s. 6d. tea, a slightly inferior at 2s 3d., and a
cheap Indian at 1s. 9d., but she is very particular always about her prices."
"What do you propose to do?" asked the innocent assistant.
"Do?" exclaimed the grocer. "Why, just mix up the three teas in different proportions so that the twenty
pounds will work out fairly at the lady's price. Only don't put in more of the best tea than you can help,
as we make less profit on that, and of course you will use only our complete pound packets. Don't do any
weighing."
How was the poor fellow to mix the three teas? Could you have shown him how to do it?
(Dudeney)
"""
This model was inspired by the XPress Mosel (IP) model created by Martin Chlond.
http://www.chlond.demon.co.uk/puzzles/sol2s4.html
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 =>
Tea = 3,
Price = [30,27,21],
X = new_list(Tea),
X :: 0..20,
Total #= sum([X[I]*Price[I] : I in 1..Tea]),
foreach(I in 1..Tea) X[I] #>= 0 end,
% 20 pound * 2s 4 1/2d = 20 * (24+4+1/2) = 570
sum([Price[I]*X[I] : I in 1..Tea]) #= 570,
sum(X) #= 20, % twenty pound
solve($[min(Total)],X),
println(total=Total),
println(x=X),
nl.