Re: [Tutor] improving the speed of prime number code

2009-02-06 Thread bob gailer
H.G. le Roy wrote: Hi, I'm stuck with Problem 10 (http://projecteuler.net/index.php?section=problems&id=10 ) :-) A part of my code deals with the calculation of prime numbers. However it is really slow. Hopefully you have some ideas

Re: [Tutor] improving the speed of prime number code

2009-02-06 Thread Kent Johnson
On Fri, Feb 6, 2009 at 4:19 PM, H.G. le Roy wrote: > A part of my code deals with the calculation of prime numbers. However it is > really slow. Hopefully you have some ideas how to make it faster. > > pz = [2] > # only iterate over odd numbers > for i in xrange(3,200,2): > remprod = 1 # p

Re: [Tutor] improving the speed of prime number code

2009-02-06 Thread taserian
One potential way to speed up is not to divide by every prime in your pz list, but only up to the square root of i. For example, to test if 37 is prime, you would only need to look at primes less than or equal to int(sqrt(37)) = 6.08. . . Tony R. On Fri, Feb 6, 2009 at 4:19 PM, H.G. le Roy wrot

[Tutor] improving the speed of prime number code

2009-02-06 Thread H.G. le Roy
Hi, I'm stuck with Problem 10 ( http://projecteuler.net/index.php?section=problems&id=10) :-) A part of my code deals with the calculation of prime numbers. However it is really slow. Hopefully you have some ideas how to make it faster. pz = [2] # only iterate over odd numbers for i in xrange(3,