""" 365 days in the year N people in the room 2 people: chances of same birthday: 1/365 1 person in room: can't collide 2 person in the room 364/365 p 3 person in room (363/365) * (364/365) p 4 person in room (362/365) * (363/365) * (364/365) """ # 10*9*8 # # 10*9*8*7*6*5*4*3*2*1 10! / (10-3)! # 7*6*5*4*3*2*1 def birthday(n, m): """ probability of at least two overlaps with n things out of m slots """ # m = 365 is the birthday problem # product of (m-1)*(m-2)*(m-3)*..../m*m*m*... # ---- n-1 terms ------ --- n-1 terms ------ p = 1 for i in range(1, n): p = p * (m-i)/m return 1 - p for x in range(1, 30): print(f"birthday({x}) is {birthday(x,365)}.")