Skip to content

Commit

Permalink
#1593 add the calculation script for 5.4-5
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtask committed Dec 16, 2024
1 parent c27fd56 commit 44a9c55
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions scripts/calculations/5.4-5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import math


def probability_exactly_i_pairs_have_matching_birthdays(i, k, n):
return math.factorial(k) / n ** k * math.comb(n, i) * math.comb(n - i, k - 2 * i) / 2 ** i


def probability_k_people_have_same_birthday(k, n):
prob = 1.0
for i in range(0, k // 2 + 1):
prob -= probability_exactly_i_pairs_have_matching_birthdays(i, k, n)
return prob


n = 365
k = 3
while probability_k_people_have_same_birthday(k, n) < 0.5:
k += 1
print("""minimum number of people for which the probability\
that three people have the same birthday\
is at least 1/2:""", k)

0 comments on commit 44a9c55

Please sign in to comment.