Last active
October 30, 2022 05:22
-
-
Save avi-levy/0ca97f5d33028b3e4f399f9dd20b69b8 to your computer and use it in GitHub Desktop.
Evaluating formula for math.SE batched coupon collector problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://math.stackexchange.com/questions/3278200/box-of-10-chocolates/3278285 | |
from math import factorial | |
from fractions import Fraction | |
def binom(n,k): # binomial coefficient n choose k | |
return 0 if n < k else factorial(n)/factorial(k)/factorial(n-k) | |
def e(n,m): # expected number of days to replace all n chocolates if replaced m at a time | |
return binom(n,m)*sum(Fraction(pow(-1,s+1)*binom(n,s),binom(n,m)-binom(n-s,m)) for s in range(1,n+1)) | |
e(10,3) # Fraction(8241679, 911064) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment