John Miller wrote:
How does one actually use this module? For example:
>>> import eratosthenes
>>> eratosthenes.primes()
>>> eratosthenes.primes().next()
2
>>> eratosthenes.primes().next()
2
>>> eratosthenes.primes().next()
2
How does one get beyond the first prime?
it = eratosthenes.primes()
On Mar 24, 2005, at 6:01 AM, C Smith <[EMAIL PROTECTED]> wrote:
What follows is an attempt based on the previous tutor-evolved sieve
that extends the range in which to find the next prime by a factor of
2 over the last known prime. A similar algorithm is on ASPN (I
bellieve), under
Space-efficient
Now it would be fine to have an *equally fast*
infinite prime number generator.
Has anybody any suggestions?
[cut]
What follows is an attempt based on the previous tutor-evolved sieve
that extends the range in which to find the next prime by a factor of
2 over the last known prime. A similar alg
On Wednesday, Mar 23, 2005, at 04:00 America/Chicago,
[EMAIL PROTECTED] wrote:
Now it would be fine to have an *equally fast*
infinite prime number generator.
Has anybody any suggestions?
I think when you add the condition of it being an infinite generator,
you are changing the rules and can't e
C Smith schrieb:
Hi Gregor,
I had done the same thing. I also noted that assigning (or inserting)
an element into a list is faster than creating a new list: l.insert(0,2)
is faster than l = [2]+l.
###
def sieve (maximum):
if maximum < 2: return []
limit = int(maximum**0.5)
nums
Hi Gregor,
I had done the same thing. I also noted that assigning (or inserting)
an element into a list is faster than creating a new list:
l.insert(0,2) is faster than l = [2]+l.
###
def sieve (maximum):
if maximum < 2: return []
limit = int(maximum**0.5)
nums = range(1,maximum+
Hi Sean!
Thanks for your measurements.
In the meantime I did another amendment,
leaving out the even numbers from the sieve.
It goes like this:
def sieve(maximum):
nums = range(3, maximum+1, 2)
for p in nums:
if p:
if p*p > maximum: break
start = (p*p-2)//2
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
karlSi
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
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
Gregor Lingl said unto the world upon 2005-03-18 19:57:
Hi Danny!
Preliminary remark: I know that "beautiful" and "beauty"
are concepts very seldom applied to computer programs or
programming languages. I suppose mainly because they are
to a large extent a matter of taste ...
Hi Gregor and all,
Tho
Pierre Barbier de Reuille wrote:
def sieve( max ):
max_val = int( sqrt( max ) )
s = Set(xrange( 4, max, 2 ))
for i in xrange( 3, max_val, 2 ):
s.update( xrange( 2*i, max, i ) )
return [ i for i in xrange( 2, max ) if i not in s ]
just for grins, here is the same (mostly) code in haskell
Concerning my previous posting - perhaps it
would suffice to summarize:
While Python is a language for the "pragmatic" lover,
Scheme is much more "fundamentalistic".
(thought-) *PROVOKING*?
Gregor
___
Tutor maillist - Tutor@python.org
http://mail.pytho
Hi Danny!
Preliminary remark: I know that "beautiful" and "beauty"
are concepts very seldom applied to computer programs or
programming languages. I suppose mainly because they are
to a large extent a matter of taste ...
Nevertheless: regardeless of the fact that I'm not a very
skilled scheme-progr
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
Gregor Lingl a écrit :
Hi!
Who knows a more concise or equally concise but more efficient
expression, which returns the same result as
[x for x in range(2,100) if not [y for y in range(2,x) if x%y==0]]
Gregor
P.S.: ... or a more beautiful one ;-)
___
Tuto
On Mar 18, 2005, at 02:15, Kent Johnson wrote:
Max Noel wrote:
#!/usr/bin/env python
import math
import timeit
def primeConcise(limit):
return [2] + [x for x in xrange(3, limit, 2) if not [y for y in
[2] + range(3,x,2) if x%y==0]]
def primeConciseOptimized(limit):
return [2] + [x for x in
Danny Yoo wrote:
Here is one that's traduced... er... adapted from material from the
classic textbook "Structure and Interpretation of Computer Programs":
##
from itertools import ifilter, count
def notDivisibleBy(n):
... def f(x):
... return x % n != 0
... return f
...
def siev
On Thursday, Mar 17, 2005, at 17:49 America/Chicago,
[EMAIL PROTECTED] wrote:
On my system, it took 415 seconds to generate a list of primes < 50,000
using range, but only 386 seconds if I use the same code, but with
xrange instead.
If you only calculate y up to sqrt(x) you will see a dramatic
Max Noel wrote:
#!/usr/bin/env python
import math
import timeit
def primeConcise(limit):
return [2] + [x for x in xrange(3, limit, 2) if not [y for y in [2]
+ range(3,x,2) if x%y==0]]
def primeConciseOptimized(limit):
return [2] + [x for x in xrange(3, limit, 2) if not [y for y in [2]
+
On Mar 17, 2005, at 23:54, Danny Yoo wrote:
Hi Gregor,
Here is one that's traduced... er... adapted from material from the
classic textbook "Structure and Interpretation of Computer Programs":
Ooh, nifty.
Okay, I decided to learn how to use the timeit module, so I used it to
compare my algor
On Thu, 17 Mar 2005, Gregor Lingl wrote:
> Hi!
> Who knows a more concise or equally concise but more efficient
> expression, which returns the same result as
>
> [x for x in range(2,100) if not [y for y in range(2,x) if x%y==0]]
Hi Gregor,
Here is one that's traduced... er... adapted from ma
Quoting Gregor Lingl <[EMAIL PROTECTED]>:
> [x for x in range(2,100) if not [y for y in range(2,x) if x%y==0]]
Heh. That's quite neat.
I can only offer one suggestion --- if you replace range with xrange, you get a
small speed improvement.
eg: On my system, it took 415 seconds to generate a li
On Mar 17, 2005, at 22:28, Gregor Lingl wrote:
Hi!
Who knows a more concise or equally concise but more efficient
expression, which returns the same result as
[x for x in range(2,100) if not [y for y in range(2,x) if x%y==0]]
Gregor
P.S.: ... or a more beautiful one ;-)
Hmm... I don't have "beauti
24 matches
Mail list logo