Re: [Tutor] primes (generator)

2005-03-20 Thread Gregor Lingl
Karl Pflästerer schrieb: On 19 Mrz 2005, [EMAIL PROTECTED] wrote: [Code] Maybe sombody likes... I did it ... : def sieve (max): max = max + 1 border = round(max**0.5) nums = range(0, max) nums[0] = nums[1] = None for p in nums: if p: if p = border: break

Re: [Tutor] primes (generator)

2005-03-20 Thread Sean Perry
Gregor Lingl wrote: The following variation of your sieve, using extended slice assignment seems to be sgnificantly faster. Try it out, if you like. Here are the numbers: Primes 1 - 1,000,000 timing: extendedSliceSieve: 0.708388 seconds listPrimes: 0.998758 seconds

Re: [Tutor] primes (generator)

2005-03-19 Thread Karl Pflästerer
On 19 Mrz 2005, [EMAIL PROTECTED] wrote: [Code] Maybe sombody likes to compare these algorithms to the ones mentioned before in this thread. I would be interested in the results. I did it and on my machine here (a slow one) the following straight forward version is the fastest one. It's no

Re: [Tutor] primes (generator)

2005-03-18 Thread Gregor Lingl
Hi all of you! Many thanks for your remarks, ideas and experiments. When I posted my input yesterday: [x for x in range(2,100) if not [y for y in range(2,x) if x%y==0]] my intention was indeed to find a shortest a program, disregarding efficiency. Thus range instead of xrange etc. (About one year