Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question
    
Is this a homework question? If so, you should tag it as homework and make this clear. –  madprob Jan 8 at 17:17
    
Just to be clear about what you mean, is HTHTT a case where $x=2$ heads come up before $y=2$ consecutive tails? Or did you mean to say "$x$ consecutive heads"? –  Barry Cipra Jan 8 at 17:42
    
@BarryCipra, Yes, the heads do not need to be consecutive. –  user27 Jan 8 at 17:46
    
@madprob, This is not a homework or interview question. Reading my own post, I realize it might come across as such. I've searched this site for a while and have found the answer to both individual cases (either x heads or y consecutive tails), but not how to combine them. –  user27 Jan 8 at 17:49

1 Answer 1

up vote 0 down vote accepted

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}$

share|improve this answer
    
Thank you! Though this does not answer my question exactly, since I was asking for a specific maximum number of tosses. On second thought, I don't actually need to know this, so I marked your answer as accepted. –  user27 Jan 9 at 16:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.