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).
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