September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,4 +1,7 @@
|
|||
from operator import mul
|
||||
from functools import reduce
|
||||
|
||||
|
||||
def comb(n,r):
|
||||
''' calculate nCr - the binomial coefficient
|
||||
>>> comb(3,2)
|
||||
|
|
@ -11,7 +14,10 @@ def comb(n,r):
|
|||
38760
|
||||
'''
|
||||
|
||||
if r > n-r: # for smaller intermediate values
|
||||
r = n-r
|
||||
return int( reduce( mul, range((n-r+1), n+1), 1) /
|
||||
reduce( mul, range(1,r+1), 1) )
|
||||
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