+ 7
How to write code i python for combination i,e (nCr)? Using function..
nCr = n! / (r! *n-r!)
2 Answers
+ 7
from math import factorial as f
# binomial coefficient
def bc(n, k):
return f(n)/(f(k)*f(n-k))
+ 7
Yes, that would save some computations. Not sure if it would be faster though because the math module is written in C and your additional code wouldn't be.