Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,23 @@
|
|||
from operator import mul
|
||||
from functools import reduce
|
||||
|
||||
|
||||
def comb(n,r):
|
||||
''' calculate nCr - the binomial coefficient
|
||||
>>> comb(3,2)
|
||||
3
|
||||
>>> comb(9,4)
|
||||
126
|
||||
>>> comb(9,6)
|
||||
84
|
||||
>>> comb(20,14)
|
||||
38760
|
||||
'''
|
||||
|
||||
if r > n-r:
|
||||
# r = n-r for smaller intermediate values during computation
|
||||
return ( reduce( mul, range((n - (n-r) + 1), n + 1), 1)
|
||||
// reduce( mul, range(1, (n-r) + 1), 1) )
|
||||
else:
|
||||
return ( reduce( mul, range((n - r + 1), n + 1), 1)
|
||||
// reduce( mul, range(1, r + 1), 1) )
|
||||
Loading…
Add table
Add a link
Reference in a new issue