% Entre   Cost Calories  P(hot) P(cold)
% Burger  1.00 1000      0.5    0.5
% Chicken 2.00 600       0.8    0.2
% Fish    3.00 400       0.9    0.1
% Tofu    8.00 200       0.6    0.4

% 1 = B + C + F + T
% 350 = 1000 B + 600 C + 400 F + 200 T
% S = B log2(1/B) + C log2(1/C) + F log2(1/F) + T log2(1/T)
% L = S - (a - log2(e)) (B + C + F + T - 1) 
%     - b (1000 B + 600 C + 400 F + 200 T - 350)

% a
% 0 = B + C + F + T - 1
% 0 = 1000 B + 600 C + 400 F + 200 T - 350

% b
% p(Ai) = 2^(-a) 2^(-b * g(Ai))
% B = 2^(-a) 2^(-b * 1000)
% C = 2^(-a) 2^(-b * 600)
% F = 2^(-a) 2^(-b * 400)
% T = 2^(-a) 2^(-b * 200)

% c
% a = log2(2^(-b * 1000) + 2^(-b * 600) + 2^(-b * 400) + 2^(-b * 200))

% d
% f(b) = (1000 - 350) * 2^(-b * (1000 - 350))
%     + (600 - 350)  * 2^(-b * (600  - 350))
%     + (400 - 350)  * 2^(-b * (400  - 350))
%     + (200 - 350)  * 2^(-b * (200  - 350))

% e
% f(0) = 1000 + 600 + 400 + 200 - 4 * 350 = 800 > 0

% f
b = fzero(inline('(1000 - 350) * 2^(-b * (1000 - 350)) + (600 - 350)  * 2^(-b * (600  - 350)) + (400 - 350)  * 2^(-b * (400  - 350)) + (200 - 350)  * 2^(-b * (200  - 350))'), 3)
% b = 0.0045

% g
log2 = inline('log(x)/log(2)');
a = log2(2^(-b * 1000) + 2^(-b * 600) + 2^(-b * 400) + 2^(-b * 200))
% a = 0.0157

% h
B = 2^(-a) * 2^(-b * 1000) % 0.0425
C = 2^(-a) * 2^(-b * 600)  % 0.1496
F = 2^(-a) * 2^(-b * 400)  % 0.2808
T = 2^(-a) * 2^(-b * 200)  % 0.5271

% i
B + C + F + T % = 1

% j
1000*B + 600*C + 400*F + 200*T % = 350

% k
S = B*log2(1/B) + C*log2(1/C) + F*log2(1/F) + T*log2(1/T)
% S = 1.602 < 2 [ok, because we have some information already, thus need less be to characterize the missing one]

% l
% It would be possible to encode the stream of meal orders more efficiently
% than 2 bits per order by using the information we know about the probabilities
% of each meal. However, our code would then depend on the probabilities and 
% if the probabilities changed, then we would have to adapt our code. Since the
% probabilities are likely to change, it seems wiser to just use 2 bits per code
% and be free of this dependence.

