% pD + pT + pK = 1
% 900 pD + 1500 pT + 2100 pK = 1600

% a.
% i.
% pK max = 7/12 = 0.5833
solve('2100 * x + 900 * (1 - x) = 1600', 'x')
% pK min = 1/ 6 = 0.1667
solve('2100 * x + 1500 * (1 - x) = 1600', 'x')
% 1/6 <= pK <= 7/12

% ii.
% pD = (-1 +  6 pK)/6
% pT = ( 7 - 12 pK)/6
% 
[pD,pT] = solve('pD + pT + pK = 1', '900*pD + 1500*pT + 2100*pK = 1600', 'pD,pT')

pK = 1/6:0.01:7/12

hD = (-1+6.*pK)./6 .* log(6./(-1+6.*pK))./log(2);
hT = (7-12.*pK)./6 .* log(6./(7-12.*pK))./log(2);
hK = pK            .* log(1./pK)        ./log(2);

H = hD + hT + hK

% plot(pK, H)

% iii.
% max(H) % 1.5546
solve('diff((-1+6*pK)/6 * log(6/(-1+6*pK))/log(2) + (7-12*pK)/6 * log(6/(7-12*pK))/log(2) + pK * log(1/pK)/log(2),pK)=0','pK')

pK = 0.4202
pD = (-1 +  6*pK)/6 % 0.2535
pT = ( 7 - 12*pK)/6 % 0.3263
h  = (-1+6*pK)/6 * log(6/(-1+6*pK))/log(2) + (7-12*pK)/6 * log(6/(7-12*pK))/log(2) + pK * log(1/pK)/log(2) % 1.5546 [OK]

% b. The entropy must be less than the max entropy, since more information is assumed for this computation.
% c. 
pK = 0.5833
pD = (-1 +  6*pK)/6 % 0.4166
pT = ( 7 - 12*pK)/6 % 6.667e-05
h  = (-1+6*pK)/6 * log(6/(-1+6*pK))/log(2) + (7-12*pK)/6 * log(6/(7-12*pK))/log(2) + pK * log(1/pK)/log(2) % 0.9808 [OK]

% d. 
% The absolute min number of pages is simply 0; 
% the average for the other weeks has then to be 1600 * nWeeks / (nWeeks - 1) to maintain an 1600 average per week.
% From the three possible books, the min number of pages is 900;
% the average for the other weeks has then to be (1600 * nWeeks - 900) / (nWeeks - 1).

% d.
% The absolute max number of pages is 1600 * nWeeks;
% that is all the assignments are done the first week (!).
% From the three possible books, the max number of pages is 2100;
% the average for the other weeks has then to be (1600 * nWeeks - 1200) / (nWeeks - 1).
