50 Challenging Problems in Probability [Part 4]: Trials until First Success

Shelvia
2 min readDec 10, 2023

--

Hi, I’ve recently developed an interest in problems related to probability. I came across this book “Fifty Challenging Problems in Probability with Solutions” by Frederick Mosteller. I thought it would be interesting to create a series discussing these captivating problems that might arise as interview questions. Each post will feature only 1 problem, making it a series with a total of 50 parts. Let’s dive in and activate our brain cells 🧠!

Problem:

On the average, how many times must a die be thrown until one gets a 6?

Image by the author using DALL-E 3.

Solution:

We can use the geometric distribution to model the number of failures before the first success since the experiment can have an indefinite number of trials until success. The assumptions of geometric distribution are:

  • The phenomenon being modelled is a sequence of independent trials.
  • There are only two possible outcomes for each trial, often designated success (getting a 6) or failure (not getting a 6).
  • The probability of success, p = 1/6, is the same for every trial.

One can show that the expected value for the number of independent trials to get the first success is 1/p.

To prove it is simple. The probability of success on the first trial is p times 1, and the probability of success on remaining number of trials is (1–p) times 1 + the mean number of trials (additional 1 to account for the first failure). The mean number of trials does not change due to the independence assumption. Let the mean number of trials be E[X]. Then we have:

E[X] = p * 1 + (1 — p) * (1 + E[X])

Solving this equation, we obtain E[X] = 1/p. In our case, p is the probability of getting a 6 which is 1/6, and E[X] = 1/p = 6.

Therefore, the average number of trials needed to get a 6 is 6.

Python code:

import numpy as np

n_simulations = 10000
n_first_success = 0

for _ in range(n_simulations):
success = False
count = 0
while not success:
count += 1
roll = np.random.randint(1,7)
if roll == 6:
success = True
n_first_success += count

print(f'Average no. of trials needed to get a 6 = {round(n_first_success/n_simulations)}')

# Outputs:
# Average no. of trials needed to get a 6 = 6

And that’s all for this d️ie 🎲 problem. Any feedback or questions are welcome! The code is available on my Github. Check out the other problems in this series:

50 Challenging Problems in Probability

31 stories

Thank you for reading! :)

--

--

Shelvia

Researcher in Information Theory and Trustworthy AI. Addicted to puzzles and brain teasers. Interested in particle physics and neuroscience.