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

delphi - TJvHidDeviceController "DevicePath" always showing "\" -

Disabling Android home button for industry application -

asp.net mvc 3 - Unexpected "foreach" keyword after "@" character -