What is the probability that when 5 dice are rolled, the sum is a prime number?

500 Views Asked by At

What is the probability that when five dice are rolled, the sum is a prime number?

This problem is giving me a tough time. I know that there are $6^5=7776$ different possibilities, and the maximum sum is $6+6+6+6+6=30$. However, if I take, for example, $29$, how do I find the number of ways in which the dice rolls can sum to $29$ or any other prime number?

2

There are 2 best solutions below

1
On

You can use the stars and bars method.

Valid sums are: 5,7,11,13,17,19,23,29 (2,3 are not valid since the minimum on five dice is 5)

So, you want: $$x_1+x_2+x_3+x_4+x_5 = p, \forall i, 1\le x_i \le 6$$

For each of these equations, it corresponds to a similar equation:

$$y_1+y_2+y_3+y_4+y_5 = p-5, \forall i, 0\le y_i \le 5$$

Now, $p=5$ and $p=7$ are easy. There is 1 way to get a sum of 5 and $$\dbinom{2+5-1}{5-1} = \dbinom{6}{4} = 15$$ ways to get 7.

For 11 and above, we need to use Inclusion/Exclusion. We take the total number of solutions of nonnegative integers and subtract the total number of solutions that violate the upper bound for one of the variables.

For $p=11$ we have $$\dbinom{6+5-1}{5-1} - \dbinom{5}{1}\dbinom{0+5-1}{5-1} = \dbinom{10}{4}-5 = 205$$

For $p=13$, we have $$\dbinom{8+5-1}{5-1} - \dbinom{5}{1}\dbinom{2+5-1}{5-1} = 420$$

For $p=17, p=19$, we can have two upper bounds violated.

$p=17$: $$\dbinom{12+5-1}{5-1} - \dbinom{5}{1}\dbinom{6+5-1}{5-1} + \dbinom{5}{2}\dbinom{0+5-1}{5-1} = 780$$

$p=19$: $$\dbinom{14+5-1}{5-1} - \dbinom{5}{1}\dbinom{8+5-1}{5-1} + \dbinom{5}{2}\dbinom{2+5-1}{5-1} = 735$$

For $p=23$, we can violate 3 of the upper bounds: $$\dbinom{18+5-1}{5-1} - \dbinom{5}{1}\dbinom{12+5-1}{5-1} + \dbinom{5}{2}\dbinom{6+5-1}{5-1} - \dbinom{5}{3}\dbinom{0+5-1}{5-1} = 305$$

For $p=29$, we can violate 4 of the upper bounds: $$\dbinom{24+5-1}{5-1} - \dbinom{5}{1}\dbinom{18+5-1}{5-1} + \dbinom{5}{2}\dbinom{12+5-1}{5-1} - \dbinom{5}{3}\dbinom{6+5-1}{5-1} + \dbinom{5}{4}\dbinom{0+5-1}{5-1} = 5$$

Total number of ways to yield a prime: $$1+15+205+420+780+735+305+5 = 2466$$

Total probability:

$$\dfrac{2466}{6^5} = \dfrac{137}{432}$$

0
On

I wrote a Python program that gets the count for all sums. The program just adds and subtracts
(c.f. inclusion/exclusion principle).

Python Program

roll_vec = ['dummy',0,1,1,1,1,4]
sum_buckets = [0] * 31

def Increment_Dice():
    if roll_vec[1] < 6:
        roll_vec[1] = roll_vec[1] + 1
        roll_vec[6] = roll_vec[6] + 1
        return True
    else:
        for i in range(1,6):
            if roll_vec[i] < 6:
                roll_vec[i] = roll_vec[i] + 1
                roll_vec[6] = roll_vec[6] + 1
                return True
            else:
                roll_vec[6] = roll_vec[6] - 5
                roll_vec[i] = 1
        return False

while Increment_Dice():
    sum_buckets[roll_vec[6]] = sum_buckets[roll_vec[6]] + 1

for i in range(5,31):
    print(i, sum_buckets[i])

OUTPUT

5 1
6 5
7 15
8 35
9 70
10 126
11 205
12 305
13 420
14 540
15 651
16 735
17 780
18 780
19 735
20 651
21 540
22 420
23 305
24 205
25 126
26 70
27 35
28 15
29 5
30 1