0

We flip a coin $n$ times. The probability of tails is $p$.

Let $X$ be the number of occurrences of a run of heads followed by a longer run of tails. We can also agree that if the sequence begins with a run of tails that is also an occurrence (though I believe it doesn't matter in the limit as $n \to \infty$). Here are some examples:

  • $HT$: value of $X = 0$
  • $H\color{red}{TT}HHT$: value of $X = 1$
  • $\color{red}{TT}HH\color{red}{TTT}$: value of $X = 2$
  • $H\color{red}{TT}HHHTTH\color{red}{T}H\color{red}{TTT}$: value of $X = 3$

Let's define the function

$$ f_n(p) = \mathbb{E}[X]. $$

Our question concerns the value of $p$ that maximizes $f_n$ in the limit as $n \to \infty$:

Calculate $$ \lim_{n \to \infty} \arg \max_{0\leq p \leq 1} f_n(p)$$


Disclaimer: I invented this problem and have solved it myself. But I'm posting this because I think it's a nice problem and the answer turned out nice. I'm not giving my answer yet so as not to spoil it and if someone else gets the same we have verification. I thought about posting to puzzlingSE if it's more suitable but joining that community didn't work atm. If the question should be migrated there that's OK.

ploosu2
  • 12,868

1 Answers1

3

Let $$q=1-p.$$ For large $n$ the expectation satisfies $$f_n(p)\sim n\lambda(p).$$

Let $A$ be the H run length before an H to T boundary, and let $B$ be the next T run length. Their laws are

$$\Pr(A=a)=q^{a-1}p,\ a\ge1$$ and $$\Pr(B=b)=p^{b-1}q,\ b\ge1.$$

You count a boundary when $B>A$.

Calculate

$$\Pr(B>A)=\sum_{a\ge1}q^{a-1}p\sum_{b>a}p^{b-1}q=\sum_{a\ge1}q^{a-1}p\cdot p^{a}=\frac{p^2}{1-p+p^2}.$$

This gives

$$\lambda(p)=qp\cdot\frac{p^2}{1-p+p^2}=\frac{p^3(1-p)}{1-p+p^2}.$$

Set $\lambda'(p)=0$. This reduces to

$$2p^3-4p^2+6p-3=0.$$ The root in $(0,1)$ is $$p^*\approx0.722119908924835.$$

user110311
  • 456
  • 2
  • Nice, this is the result I got too. There's also a formula for $p^* = \frac{4-2\cdot 10^\frac{1}{3} + 10^{\frac{2}{3}}}{6}$. It's clever to "do the limit" first. I calculated a formula for $f_n(p)$ (it's a little different for $n$ even and odd) but then noticed that you can get rid of parts of it (terms of the form $(pq)^n$) and in what's left the coefficient of $n$ must be $0$ when we solve for the zero of the derivative. – ploosu2 Nov 14 '25 at 14:57