Skip to content

Instantly share code, notes, and snippets.



Created Oct 30, 2019
What would you like to do?
Math 3414931
from functools import lru_cache
def binom(n, k):
if n < 0 or k < 0 or k > n:
return 0
rv = 1
for i in range(k):
rv = rv * (n - i) // (i + 1)
return rv
def sum_rp(n, k, i, c):
return sum(binom(rp - 1, c) * binom(n-rp, i-c-1) / binom(n-1, i-1) for rp in range(1, n+1))
def sum_r(n, i, c, l):
return sum(binom(r-1, c) * binom(n-r, i-c-1) for r in range(l, n+1))
def sum_c(n, k, i):
return sum(sum_r(n, i, c, n-k+1) / sum_r(n, i, c, c+1) * sum_rp(n, k, i, c) for c in range(1, i))
def sum_i(n, k):
return sum(sum_c(n, k, i) for i in range(1, n+1)) / n
for n in range(1, 10):
print([sum_i(n, k) for k in range(1, n+1)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment