Solution (source code)

= Solution

For a finite stopping time $n$ with target $k\geq1$, necessarily $n\geq k$. The last toss must be a head and the preceding $n-1$ tosses must contain $k-1$ heads. The <negative binomial stopping argument> therefore gives <likelihood> $\binom{n-1}{k-1}p^k(1-p)^{n-k}$ for the biased coin, and $\binom{n-1}{k-1}2^{-n}$ for the fair coin. Applying <Bayes' theorem> again yields
$$
\boxed{\mathbb P(B\mid\text{the }k\text{th head occurs at toss }n)
=\frac{p^k(1-p)^{n-k}}{p^k(1-p)^{n-k}+2^{-n}}}.
$$
The two experiments have different combinatorial coefficients, but each coefficient is independent of the coin parameter. Thus <posterior equality for proportional likelihoods> explains their identical posterior formula. If $p=0$, a finite positive-head stopping observation has zero <likelihood> under the biased coin, consistently giving posterior zero. If the target is $k=0$, the experiment stops at $n=0$ without a toss and the posterior remains $1/2$; a positive stopping time would then be impossible.