Author rhettinger
Recipients mark.dickinson, pablogsal, rhettinger, serhiy.storchaka, tim.peters
Date 2019-06-16.06:59:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1560668374.5.0.803230906803.issue37295@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2019-06-16 06:59:34rhettingersetrecipients: + rhettinger, tim.peters, mark.dickinson, serhiy.storchaka, pablogsal
2019-06-16 06:59:34rhettingersetmessageid: <1560668374.5.0.803230906803.issue37295@roundup.psfhosted.org>
2019-06-16 06:59:34rhettingerlinkissue37295 messages
2019-06-16 06:59:34rhettingercreate