Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:

Optimizations 2 and 3 look something like this:

    bc75 = [comb(75, r) for r in range(75//2+1)]
    bc150 = [comb(150, r) for r in range(150//2+1)]
    bc225 = [comb(225, r) for r in range(225//2+1)]

    def comb(n, k):
        if n < 0 or k < 0: raise ValueError
        if k > n: return 0
        k = min(k, n-k)
        if k > n // 3 and n < 100_000:
            return factorial(n) // (factorial(r) * factorial(n-r))
        if 75 <= n <= 75 + k:
            c, num, den, times = bc75[75-(n-k)], 75+1, 75-(n-k)+1, n-75
        elif 150 <= n <= 150 + k:
            c, num, den, times = bc150[150-(n-k)], 150+1, 150-(n-k)+1, n-150
        elif 225 <= n <= 225 + k:
            c, num, den, times = bc225[225-(n-k)], 225+1, 225-(n-k)+1, n-225
        else:
            c, num, den, times = 1, n-k+1, 1, k
        for i in range(times):
            c = c * num // den
            num += 1
            den += 1
        return c

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37295>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to