In [1]:
# Solution 1
from scipy.misc import comb
print comb(40,20, exact=True)
In [2]:
# A native implementation of N choose K from StackOverflow
from operator import mul # or mul=lambda x,y:x*y
from fractions import Fraction
def nCk(n,k):
return int( reduce(mul, (Fraction(n-i, i+1) for i in range(k)), 1) )
nCk(40,20)
Out[2]:
In [ ]: