Estimating the Probability of a Dice Sum Exceeding a Target
Arrays & HashingAuto-graded · 19 test casesLast updated
Apply the central limit theorem and continuity correction to approximate the tail probability of a sum of independent discrete random variables.
You roll a standard fair six-sided die exactly 1,000 times. All rolls are independent. Let S denote the total of all 1,000 face values.
Write a function that estimates the probability that S is strictly greater than a given integer threshold t.
Your solution should:
- Compute the expected value and variance of S from the distribution of a single roll.
- Apply a standard normal approximation justified by the central limit theorem.
- Use a continuity correction to account for the discrete nature of S.
- Handle edge cases where t falls outside the possible range of S.
Return the estimated probability as a float between 0.0 and 1.0.
Constraints
- 0 ≤ t ≤ 10,000
- The number of rolls is fixed at 1,000.
- Each die shows a value from 1 to 6 with equal probability.
- You may use standard library functions for the normal distribution or the complementary error function.
Examples
Example 1
Input: estimate_dice_sum_probability(600)
Output: 1
Hints
Hint 1
Start by finding the mean and variance of a single die roll, then scale them to 1,000 independent rolls.
Hint 2
Because S takes only integer values, P(S > t) equals P(S ≥ t + 1). Apply the continuity correction by evaluating the normal CDF at t + 0.5.
Hint 3
Check whether t lies outside the possible range [1000, 6000] before applying the approximation.
Worked solution
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Approach
The sum of many independent identically distributed random variables follows an approximately normal distribution by the central limit theorem. We leverage this fact along with a continuity correction to estimate the tail probability.
Step 1: Moments of a Single Roll
A fair six-sided die shows each face with probability 1/6. The expected value is:
E[X] = (1 + 2 + 3 + 4 + 5 + 6) / 6 = 3.5
The second moment is:
E[X²] = (1 + 4 + 9 + 16 + 25 + 36) / 6 = 91/6
The variance is:
Var(X) = E[X²] − (E[X])² = 91/6 − (7/2)² = 91/6 − 49/4 = 35/12
Step 2: Moments of the Sum
For 1,000 independent rolls, linearity of expectation gives:
E[S] = 1000 × 3.5 = 3500
Because the rolls are independent, variances add:
Var(S) = 1000 × (35/12) ≈ 2916.67
The standard deviation is:
σ(S) = √(1000 × 35/12) ≈ 54.01
Step 3: Normal Approximation with Continuity Correction
By the central limit theorem, S is approximately normal with mean 3500 and standard deviation ~54.01. Since S is integer-valued, we apply a continuity correction:
P(S > t) = P(S ≥ t + 1) ≈ P(Z > (t + 0.5 − 3500) / 54.01)
where Z is a standard normal random variable. We compute this tail probability using the complementary error function.
Step 4: Range Checks
The minimum possible sum is 1,000 (all ones) and the maximum is 6,000 (all sixes). If t < 1000, the probability is 1. If t ≥ 6000, the probability is 0.
Why This Works
The central limit theorem guarantees that the normalized sum converges in distribution to a standard normal. The continuity correction accounts for the discrete nature of S and improves accuracy, especially near the mean. For extreme thresholds far in the tail, the approximation remains reasonable because 1,000 rolls provide sufficient sample size.
Complexity
- Time: O(1) — constant-time arithmetic and one function call.
- Space: O(1) — no additional storage.
import math
def estimate_dice_sum_probability(t: int) -> float:
# The minimum sum is 1000 (all ones) and maximum is 6000 (all sixes).
if t < 1000:
return 1.0
if t >= 6000:
return 0.0
# Single die: mean = 3.5, variance = 35/12
mean_total = 1000 * 3.5
variance_total = 1000 * (35.0 / 12.0)
std_dev = math.sqrt(variance_total)
# Continuity correction: P(S > t) = P(S >= t+1) ≈ P(Z > (t+0.5 - μ)/σ)
z = (t + 0.5 - mean_total) / std_dev
# P(Z > z) = 0.5 * erfc(z / sqrt(2))
return 0.5 * math.erfc(z / math.sqrt(2.0))