[Edu-sig] what? (late nite entertainment) (*)

Terry Hancock hancock at anansispaceworks.com
Thu Jan 29 08:31:48 EST 2004


On Wednesday 28 January 2004 11:22 pm, Stephen Thorne wrote:
> More correctly, it generates a list of numbers less than n, then removes 
> all numbers from that list that aren't prime. Also, it breaks if n < 3.

It also breaks with Python <= 2.2.  Try this instead if you are so encumbered,
like me:

def what(n):
     x,y = range(n), [0]*n
     x[1]= 0
     z = 0
     while z*z <= n:
         z+=1
         if x[z]:                      
             for i in range(z*z, n, z): x[i]=y[i]
     return [z for z in x if z]


--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com



More information about the Edu-sig mailing list