algos/misc/birthday_problem.py

17 lines
349 B
Python

def p_all_different(n):
p = 1
free_days = 365
days_year = 365
for i in range(0, n):
p = p * (free_days / days_year)
free_days -= 1
return p
if __name__ == "__main__":
for i in range(1, 30):
print(f"p_all_different({i})={p_all_different(i)}")
if p_all_different(i) < 0.5:
break