On Apr 16, 6:40 pm, Anton Vredegoor <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Isn't that what docstrings are for? Can't you leave
> > the function name noverk() and add something to the
> > effect of "this function calculates combinations"?
> > Then it would show up in searches, wou
[EMAIL PROTECTED] wrote:
> Isn't that what docstrings are for? Can't you leave
> the function name noverk() and add something to the
> effect of "this function calculates combinations"?
> Then it would show up in searches, wouldn't it?
Yes, a doc string would help finding it in searches, however
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > You could take it up with the gmpy author and
> > induce him to get gmpy included in the standard distro if you are so
> > inclined.
>
> Alex Martelli knows more about that subject than I and
> it would be pointless for me to bug him about it.
gmp
On Apr 15, 4:16?pm, Anton Vredegoor <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> >> We're getting closer and closer to something I already posted a few
> >> times here. This implementation was unfortunate because I consistently
> >> used an uncommon name for it so people couldn't easily
On Sun, 15 Apr 2007 13:58:38 -0700, Mark Dickinson wrote:
> ... for large n and k it's difficult to imagine any real-world
> applications that wouldn't be better served by using the lngamma
> function instead. That is, the natural log of n choose k can be
> computed much more quickly as
>
> lnga
[EMAIL PROTECTED] wrote:
>> We're getting closer and closer to something I already posted a few
>> times here. This implementation was unfortunate because I consistently
>> used an uncommon name for it so people couldn't easily find it
>
> But then, who's looking for it?
The OP was trying to fin
On Apr 15, 3:33 pm, [EMAIL PROTECTED] wrote:
> With few tests, it seems this is faster than the version by Jussi only
> with quite big n,k.
>
True---and for large n and k it's difficult to imagine any real-world
applications that wouldn't be better served by using the lngamma
function instead. Th
On Apr 15, 11:34�am, Anton Vredegoor <[EMAIL PROTECTED]>
wrote:
> Jussi Piitulainen wrote:
> >> There's probably even a really clever way to avoid that final
> >> division, but I suspect that would cost more in time and memory than
> >> it would save.
>
> We're getting closer and closer to somethin
Mark Dickinson:
> def choose(n, k):
> ntok = 1
> for t in xrange(min(k, n-k)):
> ntok = ntok*(n-t)//(t+1)
> return ntok
With few tests, it seems this is faster than the version by Jussi only
with quite big n,k.
(Another test to be added, is the assert n>0 of my original versio
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:
Jussi Piitulainen wrote:
>> There's probably even a really clever way to avoid that final
>> division, but I suspect that would cost more in time and memory than
>> it would save.
We're getting closer and closer to something I already posted a few
times here. This implementation was unfortunate
On Apr 15, 8:37 am, Jussi Piitulainen <[EMAIL PROTECTED]>
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:
>
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 b
Steven D'Aprano:
> 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 implementation would be something like this:
You are right, thank you for the improvement (t
On Sun, 15 Apr 2007 02:38:31 -0700, bearophileHUGS wrote:
> DanielJohnson:
>> Please help, I couldnt find the function through help.
>
> You can't find it because it's not there:
>
> def factorial(n):
> """factorial(n): return the factorial of the integer n.
> factorial(0) = 1
> fact
DanielJohnson:
> Please help, I couldnt find the function through help.
You can't find it because it's not there:
def factorial(n):
"""factorial(n): return the factorial of the integer n.
factorial(0) = 1
factorial(n) with n<0 is -factorial(abs(n))
"""
result = 1
for i in
DanielJohnson <[EMAIL PROTECTED]> wrote:
> how to use the combination function in python ?
>
> For example 9 choose 2 (written as 9C2) = 9!/7!*2!=36
>
> Please help, I couldnt find the function through help.
If you download and install gmpy, it's easy:
>>>
how to use the combination function in python ?
For example 9 choose 2 (written as 9C2) = 9!/7!*2!=36
Please help, I couldnt find the function through help.
--
http://mail.python.org/mailman/listinfo/python-list
18 matches
Mail list logo