Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > 0a30b3a9f9f116957655e4520b1f2301 > files > 512

python-cython-0.19.1-4.mga4.x86_64.rpm

import cmath

def nCr(n, r):
    """Return the number of ways to choose r elements of a set of n."""
    return cmath.exp( cmath.lfactorial(n) - cmath.lfactorial(r)
                      - cmath.lfactorial(n-r) )

if __name__ == "__main__":
    import sys
    if len(sys.argv) != 3:
        sys.stderr.write("USAGE: %s n r\nPrints n-choose-r.\n" % sys.argv[0])
        sys.exit(2)
    n, r = map(float, sys.argv[1:])
    print nCr(n, r)