CoCalc Public FilesProject / S21 / Final Project Draft / group 4 -final project.ipynbOpen with one click!

Dice Roll Game In this game, four six-sided die is being rolled. What is the probability of where all the dice can be paired off so that one pair adds up to four and the other pair adds up to nine?

1

In [1]:

import numpy as np

2

we could create 4 dies as D1,D2,D3,D4

3

In [7]:

D1= np.random.randint(1,7) D2=np.random.randint(1,7) D3=np.random.randint(1,7) D4=np.random.randint(1,7)

4

Then, we have to list all wanted results. Which is basically all possible set of pairs, and each set has two wanted result where the first pair adds up to 7 and the second pair adds up to 9, or vice-versa. And which we got

5

(D1+D2==7 and D3+D4==9) or (D1+D2 ==9 and D3+D4==7) (D2+D3==7 and D1+D4==9) or (D2+D3 ==9 and D1+D4==7) (D2+D4==7 and D1+D3==9) or (D2+D4 ==9 and D1+D3==7)

6

After that, we can make the code that runs the simulation multiple time and when there is a run that has one of the wanted result, it return a 1, likewise, it returns 0.

7

In [2]:

def die_rolls(): D1= np.random.randint(1,7) D2=np.random.randint(1,7) D3=np.random.randint(1,7) D4=np.random.randint(1,7) if (D1+D2==7 and D3+D4==9) or (D1+D2 ==9 and D3+D4==7): return 1 elif (D2+D3==7 and D1+D4==9) or (D2+D3 ==9 and D1+D4==7): return 1 elif (D2+D4==7 and D1+D3==9) or (D2+D4 ==9 and D1+D3==7): return 1 else: return 0

8

In [3]:

sum([die_rolls() for i in range(1000000)])/1000000

9

0.074239

we estimate the probability is about 7.4239% if we try 1000000 times .

10

computer the probability

11

we know for 4 dies , total faces could estimate will be 6*6*6*6 . but as the requests, if we pick out D1,D2 , what the face that satisfy the sum(D1,D2)==7 ?

12

In [4]:

for D1 in range(1,7): for D2 in range(1,7): if D1+D2==9: print((D1,D2))

13

(3, 6)
(4, 5)
(5, 4)
(6, 3)

then another D3 and D4 , same should satisfy the sum(D3,D4)=9.

14

In [5]:

for D3 in range(1,7): for D4 in range(1,7): if D3+D4==7: print((D3,D4))

15

(1, 6)
(2, 5)
(3, 4)
(4, 3)
(5, 2)
(6, 1)

total 4 dies (D1,D2,D3,D4), so the sum(faces of dies upon the requests) satisfy the condition that sum(2 dies) is 7 and another sum(2 dies)=9 will be 4(means 4 dies)*6*(sum(2 dies)=7)*4*(sum(another 2 dies))=96
sum(faces of 4 dies)=6*6*6*6
thus , the probability=sum(faces of requests dies)/sum(faces of 4 dies )

16

In [6]:

6*4*4/6**4

17

0.07407407407407407

solution : compare the estimate by the python code and the probability analysis, the code will always have the result around the exact probability 7.407%.

18