15

I am working on a problem involving a fair 6-sided die. We roll the die at times $t = 0, 1, 2, \dots$ and stop immediately once we have rolled three consecutive 6s.

For example:

  • Sequence $6, 6, 6 \implies$ stop at $t=2$ (Even).
  • Sequence $1, 6, 6, 6 \implies$ stop at $t=3$ (Odd).

enter image description here

I need to find the probability that the stopping time $T$ is an $odd$ $number$.


I tried using states $0, 1, 2$ representing the current run of sixes. Let $P_i$ be the probability that we finish at an odd time starting from state $i$.

If I am at state 0 and roll a non-6, I waste one minute (1 step), so I essentially need the remaining time to be even to satisfy the condition? I tried setting up equations like: $$P_0 = \frac{5}{6}(1 - P_0) + \frac{1}{6}(1 - P_1)$$ But I am getting confused on the boundary conditions, specifically when moving from 2 sixes to 3 sixes.

Any help on setting up the correct system of equations would be appreciated.


Code snippet for verification

import random
import numpy as np

def run_simulation(num_trials=100000): """ Simulates the dice game to estimate the probability that the stopping time T is Odd. """ odd_count = 0

for k in range(num_trials):
    consecutive_sixes = 0
    t = 0  # Time starts at 0 (1st throw)

    while True:
        # Simulate a die roll (1 to 6)
        roll = random.randint(1, 6)

        # Update state
        if roll == 6:
            consecutive_sixes += 1
        else:
            consecutive_sixes = 0

        # Check stopping condition
        if consecutive_sixes == 3:
            # Game stops immediately.
            # If t=2 (e.g., rolls at 0,1,2), T is Even.
            # If t=3 (e.g., rolls at 0,1,2,3), T is Odd.
            if t % 2 != 0:
                odd_count += 1
            break

        # Increment time for the next throw
        t += 1
        # print(k)

return odd_count / num_trials

def calculate_theoretical(): """ Solves the linear equations for the exact probability. Let x_i be the prob that total steps remaining is ODD given we have 'i' consecutive sixes.

Equations derived:
x0 = 5/6*(1-x0) + 1/6*(1-x1)
x1 = 5/6*(1-x0) + 1/6*(1-x2)
x2 = 5/6*(1-x0) + 1/6*(1)   <-- If we roll 6 here, we stop. Steps added=1 (Odd).
"""
# Rearranging the equations into Ax = B format:
# 1. 11*x0 + 1*x1 + 0*x2 = 6
# 2. 5*x0 + 6*x1 + 1*x2 = 6
# 3. 5*x0 + 0*x1 + 6*x2 = 6

A = np.array([
    [11, 1, 0],
    [5, 6, 1],
    [5, 0, 6]
])
B = np.array([6, 6, 6])

# Solve for [x0, x1, x2]
solution = np.linalg.solve(A, B)
return solution[0]  # x0 is the probability starting from 0 sixes

if name == "main": print("--- Dice Simulation (Stopping condition: 6-6-6) ---") # 2. Simulation Result trials = 1000000 print(f"Running simulation with {trials} trials...") sim_prob = run_simulation(trials) print(f"Simulated Probability (T is Odd): {sim_prob:.6f}")

Output

Running simulation with 1000000 trials...
Simulated Probability  (T is Odd): 0.498262
  • I think it is more handsome to go for finding $P(N\text{ is odd})$ where $N$ denotes the number of trials needed. Subtracting this from $1$ gives the answer. – drhab Dec 20 '25 at 08:47
  • There are six states, for the parity of the rolls and current string of 6s – Empy2 Dec 20 '25 at 11:51
  • @Empy2 If you go for finding $P(T\text{ is even})$ then a system with $3$ states can be used (see my answer). So that is more handsome. Afterwards we find $P(T\text{ is odd})$ using the fact that their summation must equal $1$. – drhab Dec 20 '25 at 11:59
  • As for my calculation,$\frac{185}{371}\approx0.498652291105121$,$\frac{186}{371}\approx0.5013477088948787$ – thedeepdeepsky Dec 20 '25 at 14:43
  • And 10 times of 1000000 trials' simulation suggests an average of $0.49834$ – thedeepdeepsky Dec 20 '25 at 14:45
  • Almost certainly,the answer shall be $\frac{185}{371}$ – thedeepdeepsky Dec 20 '25 at 14:47
  • Please mention explicitly that each roll of the die is independent of the previous ones. – Rodrigo de Azevedo Dec 21 '25 at 14:33

6 Answers6

15

If the first roll is not a six, then the probability that we stop at an odd time is equal to the probability that we stop at an even time when we start counting after the first roll. Also, by the convention that you are following, if the first three rolls are sixes, then it is a failure (i.e. we don't stop at an odd time). So we keep conditioning on the first, second and third toss and use independence to say.

If $p$ is the probability, then

$$p=\frac{5}{6}(1-p)+\frac{1}{6}\left(\frac{5}{6}p+\frac{1}{6}\cdot\frac{5}{6}(1-p)\right)$$

We then solve the above equation to find $p$ which is $\dfrac{185}{371}$. The answer might be $1-p$ depending on which convention you want to use for counting (and stopping).

8

Apologies for originally misreading your question. I now understand your difficulty with "boundary conditions".

If the first throw is made at time $\ t=0\ $ rather than $\ t=1\ ,$ then the initial state of the Markov chain is not state $0$ almost surely, as I took it to be in my original answer, but state $0$ with probability $\ \frac{5}{6}\ $ or state $1$ with probability $\ \frac{1}{6}\ .$ The probability that $\ T\ $ is odd is therefore \begin{align} \frac{5}{6}P_0+\frac{1}{6}P_1=\frac{185}{317}\approx0.49865^\color{red}{\dagger}\ , \end{align} where $\ P_0\ $ and $\ P_1\ $ are as in my original answer below.

$\color{red}{\dagger}$ The exact decimal representation of $\ \frac{185}{371}\ $ has period $78.$

Original answer

(Based on a mistaken assumption that the time of the first toss was $\ t=1\ $ rather than $\ t=0\ $)

I don't follow why your approach needs any boundary conditions. Doesn't your technique give you the equations \begin{align} P_1&=\frac{5}{6}(1-P_0)+\frac{1}{6}(1-P_2)\\ P_2&=\frac{5}{6}(1-P_0)+\frac{1}{6} \end{align} for $\ P_1\ $ and $\ P_2\ ?$ Together with your equation for $\ P_0\ $ these constitute three linear equations for $\ P_0,P_1\ $ and $\ P_2\ ,$ whose solution is \begin{align} P_0&=\frac{186}{371}\\ P_1&=\frac{180}{371}\\ P_2&=\frac{216}{371}\ . \end{align} Coming to your specific difficulty with the move from $2$ sixes to $3$ sixes, if you're in state $2$ then with probability $\ \frac{1}{6}\ $ you'll get your three sixes in exactly one step (an odd number), and with probability $\ \frac{5}{6}\ $ you'll move to state $0,$ from which you'll then need to take an even number of steps to get your three sixes.

  • To be calculated is $P(T\text{ is odd})$ which means that not $666$ but $X666$ with $X\neq 6$ is the first favorable outcome. This indicates that $P(T\text{ is odd})<P(T\text{ is even})$ so that $P(T\text{ is odd})<\frac12$. However your $P_0$ is larger than $\frac12$. Your $P_0$ probably equals $P(N\text{ is odd})$ in my answer. – drhab Dec 20 '25 at 11:54
  • 2
    See the question. The fact that the first throw takes place at time $0$ (so not time $1$ as we would rather expect) makes things confusing. – drhab Dec 20 '25 at 12:09
  • I missed the fact that the OP started counting from $\ t=0\ $ rather than $\ t=1\ .$ This means that the OP's equation for $\ P_0\ ,$ and my extensions for $\ P_1\ $ and $\ P_2\ $ don't hold at the start of the process. However, since the stopping time will be odd when you start counting from $\ t=0\ $ if and only if it's even when you start counting from $\ t=1\ ,$ the answer to the OP's question will be $\ 1-P_0=\frac{185}{371}\ $ (using the value I obtained for $\ P_0\ ).$ – lonza leggiera Dec 20 '25 at 12:23
  • 4
    Indeed $\frac{186}{371}$ is the probability that you stop at the first available opportunity or an even number of attempts later (apparently this means even for the OP) and $\frac{185}{371}$ is the probability that you do not (apparently this means odd for the OP). – Henry Dec 20 '25 at 12:28
  • @Henry I too got $\frac{185}{371}$ in my answer. But I am still confused as to what convention the OP is following. – Mr. Gandalf Sauron Dec 20 '25 at 12:29
6

The problem can be solved in a rather rote way once you have the transition matrix. With your 3-state approach, the state diagram looks like:

  5/6      1/6      1/6      1/6      1
+----- #0 ----> #1 ----> #2 ----> #3 ----+
|       ^        |        |        ^     |
|       |        |        |        |     |
+-------+        | 5/6    |        +-----+
        |        |        | 5/6
        +--------+        |
        |                 |
        +-----------------+

This is an absorbing Markov chain with

  • several transient states: #0, #1, and #2; and
  • a single absorbing state: #3.

The transition matrix of this absorbing Markov chain is given by:

$$ \left[\begin{array}{c|c} \mathbf{Q} & \mathbf{R} \\ \hline \mathbf{0} & \mathbf{I}_1 \\ \end{array}\right] := \left[\begin{array}{ccc|c} 5/6 & 1/6 & 0 & 0 \\ 5/6 & 0 & 1/6 & 0 \\ 5/6 & 0 & 0 & 1/6 \\ \hline 0 & 0 & 0 & 1 \\ \end{array}\right]. $$

where

  • $\mathbf{Q}$ describes the transitions among the transient states,
  • $\mathbf{R}$ describes the transition from the transient states to the absorbing state, and
  • $\mathbf{I}_1$ is the 1 × 1 identity matrix.

Iteration of the transition matrix several times shows the following pattern:

$$ \begin{align} \left[\begin{array}{c|c} \mathbf{Q} & \mathbf{R} \\ \hline \mathbf{0} & \mathbf{I}_1 \\ \end{array}\right]^2 &= \left[\begin{array}{c|c} \mathbf{Q}^2 & \mathbf{R} + \mathbf{Q} \mathbf{R} \\ \hline \mathbf{0} & \mathbf{I}_1 \\ \end{array}\right] \\ \left[\begin{array}{c|c} \mathbf{Q} & \mathbf{R} \\ \hline \mathbf{0} & \mathbf{I}_1 \\ \end{array}\right]^3 &= \left[\begin{array}{c|c} \mathbf{Q}^3 & \mathbf{R} + \mathbf{Q} \mathbf{R} + \mathbf{Q}^2 \mathbf{R} \\ \hline \mathbf{0} & \mathbf{I}_1 \\ \end{array}\right] \\ \left[\begin{array}{c|c} \mathbf{Q} & \mathbf{R} \\ \hline \mathbf{0} & \mathbf{I}_1 \\ \end{array}\right]^4 &= \left[\begin{array}{c|c} \mathbf{Q}^4 & \mathbf{R} + \mathbf{Q} \mathbf{R} + \mathbf{Q}^2 \mathbf{R} + \mathbf{Q}^3 \mathbf{R} \\ \hline \mathbf{0} & \mathbf{I}_1 \\ \end{array}\right] \\ &\,\;\vdots \end{align} $$

The top-right block contains the absorbing probability

$$\mathbf{B}_n := \mathbf{R} + \mathbf{Q} \mathbf{R} + \mathbf{Q}^2 \mathbf{R} + \mathbf{Q}^3 \mathbf{R} + \cdots + \mathbf{Q}^{n - 1} \mathbf{R}.$$

in which $(\mathbf{B}_n)_{i, j}$ is the probability of reaching the absorbing state $j$ after $n$ or fewer transitions (i.e. at or before time $t = n - 1$, per OP's convention) from the transient state $i$.

However, the OP is interested in $P_i$, the probability of reaching state #3 at an odd time $t$ from the state $i$, i.e. after an even number of transitions $n$. This means we instead want

$$\begin{align*} \mathbf{P} &:= \mathbf{Q} \mathbf{R} + \mathbf{Q}^3 \mathbf{R} + \mathbf{Q}^5 \mathbf{R} + \mathbf{Q}^7 \mathbf{R} + \cdots \\ &= \mathbf{Q} \mathbf{R} + \mathbf{Q}^2 \bigl(\mathbf{Q} \mathbf{R} + \mathbf{Q}^3 \mathbf{R} + \mathbf{Q}^5 \mathbf{R} + \cdots\bigr) \\ &= \mathbf{Q} \mathbf{R} + \mathbf{Q}^2 \mathbf{P}. \\ \end{align*}$$

This geometric sum can be simplified as

$$\begin{align*} (\mathbf{I}_3 - \mathbf{Q}^2) \mathbf{P} &= \mathbf{Q} \mathbf{R} \\ \mathbf{P} &= (\mathbf{I}_3 - \mathbf{Q}^2)^{-1} \mathbf{Q} \mathbf{R} \end{align*}$$

The only challenge left is to calculating the inverse of

$$\mathbf{I}_3 - \mathbf{Q}^2 = \begin{bmatrix} 1/6 & -5/36 & -1/36 \\ -5/6 & 31/36 & 0/1 \\ -25/36 & -5/36 & 1/1 \\ \end{bmatrix}.$$

There's many ways to invert the matrix and they all lead to the same result,

$$(\mathbf{I}_3 - \mathbf{Q}^2)^{-1} = \begin{bmatrix} 40176/371 & 6660/371 & 1116/371 \\ 38880/371 & 6876/371 & 1080/371 \\ 33300/371 & 5580/371 & 1296/371 \end{bmatrix}.$$

Thus,

$$\mathbf{P} = (\mathbf{I}_3 - \mathbf{Q}^2)^{-1} \mathbf{Q} \mathbf{R} = \begin{bmatrix} 185/371 \\ 191/371 \\ 155/371 \end{bmatrix}.$$

Notably, $P_0 = 185/371$.

1

This is not a complete answer because I fail to find a solution for a recursion relation. Here I try an alternative method. I will count the number of all possible sequences $\{X_t\}_{t=0}^T$ that stops at $t=T$($T\geqslant2$).

To do that, I will firstly count the number of all possible $\{X_t\}_{t=0}^N$ that do not contain consecutive $6$s longer than $2$. Let $L_{t,l}$($0\leqslant t\leqslant N$, $l\in\{0,1,2\}$) be the number of $\{X_0,\ldots,X_t\}$ that end with $l$ consecutive $6$s, and we have $$ \begin{aligned} L_{t,0}&=5(L_{t-1,0}+L_{t-1,1}+L_{t-1,2})\\ L_{t,1}&=L_{t-1,0}\\ L_{t,2}&=L_{t-1,1} \end{aligned} $$ with the boundary conditions $L_{0,0}=5$, $L_{0,1}=1$ and $L_{0,2}=0$.
From this we can conclude that $L_{0,2}=0$, $L_{1,2}=1$ and $L_{2,2}=5$ and $$ L_{t,2}=5(L_{t-1,2}+L_{t-2,2}+L_{t-3,2}) $$

The probability of stopping at $t=T$ is $$ P(T)=\frac{L_{T-1,2}}{6^{T+1}} $$ So we can give $$ P(T)=\frac{5}{6}P(T-1)+\frac{5}{36}P(T-2)+\frac{5}{216}P(T-3) $$ with the boundary conditions $P(2)=\dfrac{1}{216}$, $P(3)=\dfrac{5}{1296}$, $P(4)=\dfrac{5}{1296}$.

I am not an expert of solving the exact $P(T)$ so I have to stop here. $$ P(T\;\text{is odd})=P(3)+P(5)+\ldots $$

JC Q
  • 2,783
0

Let $N$ denote the number of trials that are needed. Then clearly: $$P(T\text{ is odd})=1-P(N\text{ is odd})$$

Then we go for finding $P(N\text{ is odd})$.

As you proposed we discern states $0,1,2$ accompanied with propabilities $P_i$ where now $P_i$ denotes the propability that an odd number of trials is needed if we start in state $i$.

Then for $P_2$ (corresponding with state $2$, i.e. the state that troubles you) we have the equality: $P_2=\frac16+\frac56(1-P_0)$. Essential is here that $1$ is an odd number which declares the term $\frac16$ on RHS.

Of course there are also relevant equalities for $P_0$ and $P_1$ but I leave that to you.

drhab
  • 154,499
0

OP had spoken about boundary conditions.
They can arise if we model it as a game between $A$ and $B$ with $A$ winning with $3$ successive throws as per OP's intent, and boundary condition probabilities of win being $1$ for $A$ and $0$ for $B$. Then the states (in lowe case) with the indices denoting the number of successive sixes held being of the form $a_0, b_0, a_1, b_1, a_2, b_2$, and with the transition probabilities of moving from one state to another known, we get

$$a_0=\frac16b_1 + \frac56b_0 \tag1$$ $$b_0=\frac16a_1 + \frac56a_0 \tag2$$ $$b_1=\frac16a_2 + \frac56a_0 \tag3$$ $$a_1=\frac16b_2 + \frac56a_0 \tag4$$ $$b_2=\frac16\times 1 + \frac56a_0 \tag5$$ $$a_2=\frac16B\times 0 + \frac56b_0 \tag6$$

$$which~ yields~ the~ result~ \bbox[5px, border:2px solid #C00000]{a_0 = \frac{185}{371}}$$

Results from other states can also be seen in the link

Although this approach is clunkier than some previous answers, its advantage is that it can handle more complex loops in moving from state to state.