-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbirthday-problem.py
More file actions
36 lines (25 loc) · 936 Bytes
/
Copy pathbirthday-problem.py
File metadata and controls
36 lines (25 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import numpy as np
import sys
def simulate(people, n_same_bd):
''' CUSTOM ALGORITHM
for X in range(len(sample_people)):
occurences = 0
for x in range(len(sample_people)):
if sample_people[x] == sample_people[X] and x != X:
occurences += 1
if occurences == n_same_bd-1:
return 1
return 0
'''
sample_people = np.random.randint(1, 366, size=(int(people)))
if np.max(np.bincount(sample_people)) >= n_same_bd:
return 1
return 0
if __name__ == '__main__':
people, n_same_bd = sys.argv[1:]
n_rounds = 50000
simulation_match = 0
for i in range(n_rounds):
simulation_match += simulate(people, int(n_same_bd))
probability = simulation_match / n_rounds
print("{} People in a group. Probability of at least {} people with same birthday: {}".format(people, n_same_bd, probability))