Re: [Tutor] Need help speeding up algorithm.

2007-10-02 Thread Terry Carroll
Ian, thanks for cleaning this up and submitting it. I was curious what its performance would be. On Wed, 26 Sep 2007, Ian Witham wrote: > while count > 0: > fivecount += count > count /= 5 This is a great improvement, and I'm embarrased that I didn't think of it myself!

Re: [Tutor] Need help speeding up algorithm.

2007-09-25 Thread Ian Witham
On 9/26/07, Terry Carroll <[EMAIL PROTECTED]> wrote: > > On Tue, 25 Sep 2007, Ian Witham wrote: > > def numfaczeroes(n): > """ > return the count of trailing zeroes from n! > e.g., 10! = 3628800; count of trailing zeros = 2 > """ > exponent = 1 > fivecount = 0 > while (n

Re: [Tutor] Need help speeding up algorithm.

2007-09-25 Thread Ian Witham
On 9/26/07, Terry Carroll <[EMAIL PROTECTED]> wrote: > > On Wed, 26 Sep 2007, Ian Witham wrote: > > > My solution still took over 5 seconds on the Sphere Judge machine. > > How much data are they throwing at you? For the sample data they provide > on the website, your first "slow" solution finishe

Re: [Tutor] Need help speeding up algorithm.

2007-09-25 Thread Terry Carroll
On Wed, 26 Sep 2007, Ian Witham wrote: > My solution still took over 5 seconds on the Sphere Judge machine. How much data are they throwing at you? For the sample data they provide on the website, your first "slow" solution finished on my machine almost instantaneously. _

Re: [Tutor] Need help speeding up algorithm.

2007-09-25 Thread Ian Witham
> > > from itertools import count, takewhile > > def numfaczeroes2(n): > def while_(e): > return n//(5**e) > 0 > return sum(n//(5**exponent) for exponent in takewhile(while_, > count(1))) > > > It is quite a bit slower, though; probably because of the extra function > call introd

Re: [Tutor] Need help speeding up algorithm.

2007-09-25 Thread Kent Johnson
Terry Carroll wrote: > On Tue, 25 Sep 2007, Ian Witham wrote: > >> As I was using a list comprehension I wasn't sure how to make the >> calculations stop when the result of integer division == 0. > > I don't see how to do that, either. Someone on this list (sorry, I forget > who) once suggested

Re: [Tutor] Need help speeding up algorithm.

2007-09-25 Thread Terry Carroll
On Tue, 25 Sep 2007, Ian Witham wrote: > As I was using a list comprehension I wasn't sure how to make the > calculations stop when the result of integer division == 0. I don't see how to do that, either. Someone on this list (sorry, I forget who) once suggested that the list comprehension shou

Re: [Tutor] Need help speeding up algorithm. (Terry Carroll)

2007-09-25 Thread Carnell, James E
Terry, I liked your answer! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Need help speeding up algorithm.

2007-09-24 Thread Ian Witham
On 9/25/07, Terry Carroll <[EMAIL PROTECTED]> wrote: > > On Tue, 25 Sep 2007, Ian Witham wrote: > > > I am attempting to do this project > for > > the Sphere Online Judge. > > (Summary of the problem: for a given integer N, determine the number of > trailing ze

Re: [Tutor] Need help speeding up algorithm.

2007-09-24 Thread Terry Carroll
On Tue, 25 Sep 2007, Ian Witham wrote: > I am attempting to do this project for > the Sphere Online Judge. (Summary of the problem: for a given integer N, determine the number of trailing zeroes in N! For example, for N=10, N! = 3628800, so the number of t