In need of implementing a solution for this, I've read through this prior stack exchange discussion that describes an approach to the problem. I've also read this paper The Longest Run of Heads Author(s): Mark F. Schilling, but am struggling to understand the first paragraph under The Exact Distribution of the Longest Run, (where he describes a set of successful permutations). Am I wrong in the approach that I've outlined below, which seems completely different but simpler? The stack exchange discussion defines the problem as:
To find that probability that [the longest heads run of] a biased coin, having probability of heads
p, inntrials, exceedsm.
For the moment, I think we can greatly simplify the problem by phrasing it as:
To find that probability that [the longest heads run of] a biased coin, having probability of heads
p, inntrials, ismor greater.
Later we can substitute $(m+1)$ for $m$ in our formula to account for the difference in expression, (> vs >=).
We can look at $n$ trials as a set of opportunities, we'll call them run trials, to make a run of $m$.
Let's define a run trial as a single chance to make run of $m$. So in a run trial, $n=m$. Someone hands you a coin and asks you the chance of making ten heads in a row, with ten flips.
The probability of a successful run trial is: $p^{m}$
Given $n$ total trials, how many run trials do we have? We effectively have $k = n - m + 1$ run trials to find a successful outcome, (a successful run of $m$).
To explain the bit above, imagine you're flipping a coin 20 times, looking for a run of 10 heads or more. You're ninth and tenth flips come up tails. This next flip, your 11th, is you last opportunity to have a run of $m$. The number ($k$) of opportunities you have had to make a run of $m$ is $11 = 20 - 10 +1$.
Now we can say, what is the probability of a successful run of $m$ given $k$ run trails?
We know the probability of success in a single run trial:
$p^m$
The probability of an unsuccessful run trial is
$1 - p^m$
To answer the question, we ask what is the probability of not having any successful run trials, given k opportunities?
So the probability of not having any successful run of $m$ in $k$ run trials is $$(1- p^m)^k$$
Therefor, the probability of at least one run of m or greater in n total trials is:
$$1-(1-p^m)^{k}$$
We can substitute $n - m + 1$ for $k$ again to get a full expression with only the original variables.
$$1-(1-p^m)^{n - m + 1}$$
This should answer our rephrased question above. To answer the probability that the longest run exceeds $m$, we find the probability of a run of $m + 1$ or greater, substituting $m + 1$ for $m$.
And the probability that the longest run exceeds $m$ is $$1-(1-p^{(m+1)})^{n - (m + 1) + 1}$$ $$1-(1-p^{m+1})^{n - m - 1 + 1}$$ $$1-(1-p^{m+1})^{n - m}$$
To me the above answer makes sense logically, and I struggle to understand, let alone implement, the math used in other solutions for the software project I need this for. Perhaps someone could tell me where I'm going wrong, since something must be wrong with my assumptions. Thanks.