Sophie

Sophie

distrib > Mandriva > current > i586 > media > main-updates > by-pkgid > 78c129e4a46a64625b53d61bd2b90fab > files > 343

python-cython-0.15-0.1mdv2010.2.i586.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)