You have a bag with an infinite amount of marbles, 36% of them are red and 64% of them are green.
You draw 46 marbles out of the bag and place them in a circle in random order.
What are the chances of having 3, 4, or 5 red marbles next to each other?
I tried solving this graphically, but I just can't work through all the possible combinations. I can do it if the circle is small, but I don't know how to turn it into an equation for larger numbers.
This can be modeled as a finite-state absorbing Markov chain. If we are looking for $k$ or more reds in a row, then the states are the $m=2^k$ sequences or red and green marbles of length $k$ and the absorbing state is the one with $k$ red marbles. For programming, it is more convenient to make the states the numbers from $0$ through $m-1$ represented as $k$-bit binary strings ($0$-padded on the left) so that the absorbing state is $m-1$.
If the probability of a $1$ is $p$ then the probability that the chain starts in state $S$ is $p^s(1-p)^{(k-s)}$ where $s$ is the number of $1$'s in the binary representation of $S$. This gives us the initial vector $V$. It's easy to get the transition matrix $P$. From a non-absorbing state $S$ the system can only go to two states, each starting with the last $k-1$ bits of $S$ and followed by a $0$ or $1$ with probability $1-p$ or $p$ respectively.
If there are $n$ marbles in the circle, we have to compute $$X=VP^{n-k}$$ since the initial state already has $k$ marbles. The final entry of $X$ gives the probability that we have encountered at least $k$ red marbles in a row.
So far, we have not accounted for the possibility that there are $k$ red marbles that "close the ring." That is, that the chain starts with $0<j<k$ red marbles, and ends with at least $k-j$ marbles. To compute this, we have to consider each individual state $S$ that starts with $1\leq j<k$ $1's$, compute the probability of ending in a non-absorbing state that ends in at least $k-j$ $1$'s, given that we start in state $S$, and multiply by the probability of starting in state $S$. The conditional probability is computed in a manner analogous the the calculation described above.
I wrote a python script that does these calculations. The output from the script is
The first number in each line is $k$. The second number is the computed probability of ending in the absorbing state, and the third number is the additional probability from closing the ring. I broke it out this way to try to judge whether the additional computation to compute the probability of closing the ring is worthwhile. Since the number of cases we must consider increases exponentially with $k$, this is worth thinking about. Looking at the $k=5$ case, it appears that the answer is "yes", and
leakshould probably be changed to return the sum of the two probabilities.Here's my script: