I have another coin toss question:
Assume I am tossing a biased coin n times with probability p of coming up heads. What is the probability that x heads come up, before y consecutive tails?
A code example would be preferable.
probability
I have another coin toss question:
Assume I am tossing a biased coin n times with probability p of coming up heads. What is the probability that x heads come up, before y consecutive tails?
A code example would be preferable.
Best Answer
Consider the following events:
$A_{x,y}$: You observe $x$ heads before $y$ consecutive tails.
$B_{x,y}$: You observe $y$ consecutive tails before $x$ heads.
Let $X_{i}$ follow a Geometric(p). This means that $X_{i}$ denotes the number of tail counts until you observe the first head with a biased coin. Observe that, in particular, $P(A_{1,y}) = P(X_{1} < y)$.
In order to solve for the general case, consider $X_{1},\ldots,X_{x}$ i.i.d. Geometric(p). I claim that:
\begin{align*} P(A_{x,y}) = P(X_{1} < y, \ldots,X_{x} < y) = P(X_{1} < y)^{x} \end{align*}
In order to understand the claim, you can think of $X_{i}$ as the number of observed tails it takes until you observe a head after having already observed $i-1$ heads in the past. Hence, we only need to find $P(X_{1} < y)$. This is well known and equals $1-(1-p)^{y}$.
Hence, in general $P(A_{x,y}) = (1-(1-p)^{y})^{x}$