Solution (source code)

= Solution

The given four probabilities factor into independent <Bernoulli> indicators for the occurrence of $A$ and $B$ on each trial, with parameters $p$ and $r$. Independent trials make the full sequence of $A$ indicators independent of the full sequence of $B$ indicators. Let $N$ count trials strictly before the first $A$. Then $N\sim\operatorname{Geom}_0(p)$, independently of the $B$ indicators, and the desired count is their sum over these $N$ trials. Therefore \b[its distribution is $\operatorname{Geom}_0(p/[p+(1-p)r])$], as in part (b).

The word “before” excludes the stopping trial: an $AB$ on that trial stops the experiment but does not add to the count. Another check is to discard all $ab$ trials. Among the remaining relevant outcomes, stopping has probability $p/[p+(1-p)r]$ and an additional pre-stopping $B$ has the complementary probability, again giving the same zero-based <geometric distribution>.