+ 7

How to write code i python for combination i,e (nCr)? Using function..

nCr = n! / (r! *n-r!)

7th Jun 2019, 7:32 AM
Prakash Ranjan
Prakash Ranjan - avatar
2 Respostas
+ 7
from math import factorial as f # binomial coefficient def bc(n, k): return f(n)/(f(k)*f(n-k))
7th Jun 2019, 9:06 AM
Thoq!
Thoq! - avatar
+ 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.
7th Jun 2019, 10:30 AM
Thoq!
Thoq! - avatar