Re: combination function in python

2007-04-15 Thread Jussi Piitulainen
Steven D'Aprano writes: bearophileHUGS wrote: ... return factorial(n) // (factorial(k) * factorial(n-k)) That's a naive and slow implementation. For even quite small values of n and k, you end up generating some seriously big long ints, and then have to (slowly!) divide them. A better

Re: combination function in python

2007-04-15 Thread Jussi Piitulainen
Mark Dickinson writes: Jussi Piitulainen wrote: def choose(n, k): if 0 = k = n: ntok = 1 ktok = 1 for t in xrange(1, min(k, n - k) + 1): ntok *= n ktok *= t n -= 1 return ntok // ktok else: return 0

<    2   3   4   5   6   7