Solution (source code)

= Solution

Neither biscuit type can run out in this case. Treat each freely made choice as an <independent> <Bernoulli trial>, with success meaning chocolate. The number taken after $n$ choices has a <binomial distribution>, so
$$
\boxed{P_{k,n}=\binom nkp^k(1-p)^{n-k},\quad k=0,\ldots,n.}
$$
The <binomial coefficient> counts the possible success positions, and every such arrangement has the same probability. Independence of successive choices is the probabilistic model implicit in the question; identical marginal preferences alone would not imply it.