Is there a math nCr function in python? -


possible duplicates:
statistics: combinations in python
counting combinations , permutations efficiently
project euler problem in python (problem 53)

i'm looking see if built in math library in python ncr (n choose r) function:

enter image description here

i understand can programmed thought i'd check see if it's built in before do.

the following program calculates ncr in efficient manner (compared calculating factorials etc.)

import operator op def ncr(n, r):     r = min(r, n-r)     if r == 0: return 1     numer = reduce(op.mul, xrange(n, n-r, -1))     denom = reduce(op.mul, xrange(1, r+1))     return numer//denom 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -