Solution (source code)

= Solution

First evaluate the inner <lottery>: $U(\ell_1)=12p+3(1-p)=3+9p$. By <reduction of compound lotteries>, the outer <expected utility> is
$$
U(\ell_2)=2p+(1-p)(3+9p)=3+8p-9p^2
=\frac{43}{9}-9\left(p-\frac49\right)^2.
$$
Since $4/9$ lies in the permitted <real interval>, the square is minimized there. The unique maximizer and maximum <expected utility> are \b[$p=4/9$ and $U(\ell_2)=43/9$]. Directly flattening the <lottery> gives <probabilities> $p(1-p)$, $(1-p)^2$ and $p$ for the three outcomes; these sum to one and give the same expression.