Skip to content

Instantly share code, notes, and snippets.

@jkbrzt
Last active October 6, 2015 11:47
Show Gist options
  • Save jkbrzt/2988482 to your computer and use it in GitHub Desktop.
Save jkbrzt/2988482 to your computer and use it in GitHub Desktop.
Birthday paradox
from __future__ import division
from operator import mul
def Q(n):
"""
Let Q(n) be the probability that
no two people have a common birthday.
"""
y = 365
# The number of n birthdays without any duplicates.
dd = reduce(mul, range(y - n + 1, y + 1))
# The total number of n possible birthdays.
dr = y ** n
return dd / dr
def P(n):
"""Let P(n) be the probability in question."""
return 1 - Q(n)
print P(30)
print P(23)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment