How can I speed up a script that iterates over a large range (600 billion)?
Terry Reedy
tjreedy at udel.edu
Wed Jun 22 00:18:42 EDT 2011
On 6/21/2011 8:00 PM, Paul Rubin wrote:
> Terry Reedy<tjreedy at udel.edu> writes:
>>> efficient implementation will allow a solution to be obtained on a
>>> modestly powered computer in less than one minute."
>> If something really takes a minute in C,
>> allow yourself at least 10 minutes or even more with plain CPython.
>
> No.
No what? My conditional statement is correct. It turns out not to apply
here. Great.
> The idea of the Euler problems is to think up sane algorithms to
> solve them, not micro-optimize or use low level languages on crappy
> algorithms.
>
> n=600851475143
> for d in xrange(2,n):
> if d*d> n: break
> while n%d == 0: n //= d
> print n
>
> finishes on my laptop with no noticable pause.
If the best C program for a problem takes 10 seconds or more, then
applying the same 1 minute limit to Python is insane, and contrary to
the promotion of good algorithm thinking.
--
Terry Jan Reedy
More information about the Python-list
mailing list