You are on page 1of 5

24.06.2020 г. Birthday Sim.

ipynb - Colaboratory

import random

l1 = []

for _ in range(1,1500):
t = random.randint(1,100000)
l1.append(t)

print(l1)

[938235, 953670, 675712, 613520, 488317, 17455, 972868, 851880, 426870, 700161, 563753, 928338, 430662, 905393, 270519,

# Number of unique ellements

def nue(l):
l2 = []
for i in l:
if i not in l2:
l2.append(i)
# print("The list has", len(l), "ellements", len(l2), "of wich are unique")
return(l2)

len(l1) - len(nue(l1))

12

len(range(1,366))

365

def nue(l):
l2 = []
for i in l:
https://colab.research.google.com/drive/1zFA6y8fxP-D59T9C_8OMlX82ZEYfhVXF#printMode=true 1/5
24.06.2020 г. Birthday Sim.ipynb - Colaboratory

if i not in l2:
l2.append(i)
return(l2)

def bsim(people, nsims = 10000, ndays = 365):

outcome = []

for sim in range(1, nsims + 1):

l1 = []

for _ in range(1,people):
t = random.randint(1, ndays + 1)
l1.append(t)

q = (len(l1) != len(nue(l1)))

outcome.append(q)

return(sum(outcome) / len(outcome))

for k in range(1,51):
print(k, bsim(people = k, ndays = 365, nsims = 50000))

https://colab.research.google.com/drive/1zFA6y8fxP-D59T9C_8OMlX82ZEYfhVXF#printMode=true 2/5
24.06.2020 г. Birthday Sim.ipynb - Colaboratory

1 0.0
2 0.0
3 0.00254
4 0.0089
5 0.01556
6 0.0269
7 0.04066
8 0.0555
9 0.07256
10 0.0937
11 0.11798
12 0.14056
13 0.1667
14 0.19352
15 0.2238
16 0.24846
17 0.28576
18 0.31206
19 0.34912
20 0.38016
21 0.41116
22 0.44218
23 0.4777
24 0.5048
25 0.53862
26 0.56776
27 0.60086
28 0.62472
29 0.65216
30 0.68584
31 0.70502
32 0.72806
33 0.7523
34 0.77956
35 0.79536
36 0.81478
37 0.83044
38 0.8502
39 0.86358
40 0.8818
for k 41
in 0.89316
range(1,51):
print(k, bsim(people = k, ndays = 366))
42 0.90146
43 0.91392
https://colab.research.google.com/drive/1zFA6y8fxP-D59T9C_8OMlX82ZEYfhVXF#printMode=true 3/5
24.06.2020 г. Birthday Sim.ipynb - Colaboratory
44 0.92542
1 0.0
45 0.9335
2 0.0
46 0.93888
3 0.0025
47 0.94788
4 0.0078
48 0.95528
5 0.0184
49 0.9603
6 0.0271
50 0.96486
7 0.0412
8 0.0559
9 0.0716
10 0.097
11 0.1188
12 0.1368
13 0.1686
14 0.1903
15 0.221
16 0.2536
17 0.2758
18 0.3076
19 0.3474
20 0.3781
21 0.4084
22 0.4373
23 0.4645
24 0.5085
25 0.5361
26 0.5682
27 0.6074
28 0.6234
29 0.6479
30 0.6845
31 0.6979
32 0.7282
33 0.7488
34 0.7728
35 0.7911
36 0.8156
37 0.8336
38 0.8484
39 0.8635
40 0.8821
41 0.8935
42 0.9027
43 0.909
https://colab.research.google.com/drive/1zFA6y8fxP-D59T9C_8OMlX82ZEYfhVXF#printMode=true 4/5
24.06.2020 г. Birthday Sim.ipynb - Colaboratory
44 0.9222
45 0.9318
46 0.9372
47 0.9484
48 0.9538
49 0.9567
50 0.9651

bsim(people = 23, nsims = 100000)

0.47149

https://colab.research.google.com/drive/1zFA6y8fxP-D59T9C_8OMlX82ZEYfhVXF#printMode=true 5/5

You might also like