%           mass [g]   % nickel
% nickel    5         25
% quarter   5+2/3      8.33
% dollar    8.1       12.5
%

% pN + pQ + pD = 1
% 5 nN + 17/3 nQ + 8.1 nD = 2300

% a.
% nN: 0 to 460 
% nQ: 0 to 405 (+ 1 n)
% nD: 0 to 280 (+ 3 n + 3q)

% b.
% nN + nQ + nD = 400
[nQ, nD] = solve('nN + nQ + nD = 400', '5*nN + (17/3)*nQ + 8.1*nD = 2300', 'nQ,nD')

nN = 0:1:460;
nQ =  0.273972 * nN +  13.69863
nD = -1.273972 * nN + 386.30137
pN = nN/400; pQ = nQ/400; pD = nD/400;
H = pN.*log(1./pN)./log(2) + pQ.*log(1./pQ)./log(2) + pD.*log(1./pD)./log(2)

max(real(H)) % 1.4693

% max: H(188)
nN(188) % 187
nQ(188) % 65
nD(188) % 148

% c. 
mNi = (nN(188) * 5 * .25 + nQ(188) * 17/3 * .0833 + nD(188) * 8.1 * .125) / (nN(188) * 5 + nQ(188) * 17/3 + nD(188) * 8.1) % 16.56%
mCu = 1 - mNi % 83.44%

% d. We cannot have 200 dollar coins, if the jar is to contain 400 coins and weight 2300 grams. 
%    Indeed, we only need 136 (2300 - 200 * 8.1)/5) nickels to meet the 2300 grams, 
%    while having not reached 400 coins.
%    Our answer is not compatible with a, but that is OK, 
%    because in a we didn't have any indications on the total number of coins.
