>
>
> 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 introduced for while_():
>

I sped this up slightly by using a lambda function instead of while_(), but
not by much.

My solution still took over 5 seconds on the Sphere Judge machine. The top
Python solution takes around 0.6 seconds!

While I haven't submitted Terry's solution, my Timer comparisons suggest
that it would take around 1.5 seconds to process the data. This doesn't take
into account any time used inputting and outputting the test data.

If anyone knows the 0.6 second solution feel free to share!

Ian.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to