3

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?

jvdhooft
  • 7,589
  • 9
  • 25
  • 47
Math
  • 425
  • 1
    True there are $6^5$ different die rolls, but there are only $25$ different sums, and not too many of those are prime. – Matthew Leingang Aug 14 '19 at 18:55
  • 2
    The key word is generating function. There are many posts here on MSE with this content. Here is the link to the results: – callculus42 Aug 14 '19 at 18:55
  • You want positive solutions for $x_1+x_2+\dotsb+x_5=p$, where $p$ is prime number and $x_i \geq 1$ for all $i$. Are you familiar with stars and bars idea (https://en.wikipedia.org/wiki/Stars_and_bars_%28combinatorics%29)? – Anurag A Aug 14 '19 at 18:57
  • @AnuragA Note that $x_i \le 6$ for all $i$, so it's a little more complicated than the standard stars and bars. – eyeballfrog Aug 14 '19 at 19:03
  • @eyeballfrog Yes I agree. But I wasn't sure if OP is familiar with the basic idea or not. – Anurag A Aug 14 '19 at 19:05
  • Just count in an orderly fashion. 29 is easy, since you know that the only way to obtain 29 is 5 + 6 + 6 + 6 + 6, and that order can be permuted in 5 ways. Numbers in the middle have more combos. For instance, take 17. You can get 17 with 6 + 6 + 3 + 1 + 1, which permutes in (5 C 2) * 3 = 30 ways. You can also do 6 + 6 + 2 + 2 + 1, which also has 30 ways. Then count 6 + 5 + 4 + 1 + 1, which permutes in 5 * 4 * 3 = 60 ways. And so on. – K. Jiang Aug 14 '19 at 19:05
  • @Math There's been several comments regarding using generating functions. If you're not particularly familiar with them & would like to learn more, I suggest you read How can I learn about generating functions?. – John Omielan Aug 14 '19 at 20:24

2 Answers2

5

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}$$

SlipEternal
  • 10,555
  • 1
  • 17
  • 38
0

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
CopyPasteIt
  • 11,366