Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python35/share/doc/alt-python35-Cython/Demos/freeze/
Upload File :
Current File : //proc/242857/root/opt/alt/python35/share/doc/alt-python35-Cython/Demos/freeze/combinatorics.pyx

# cython: language_level=3

import lcmath


def nCr(n, r):
    """Return the number of ways to choose r elements of a set of n."""
    return lcmath.exp(
        lcmath.lfactorial(n) -
        lcmath.lfactorial(r) -
        lcmath.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))