- Code: Select all
`def prime_sieve(upper):`

'''

prime_sieve(upper) -> list of primes up to upper (not including)

'''

nums = range(upper)

p = 2

end = pow(upper, 0.5) + 1

while p < end:

for m in xrange(p + p, upper, p):

nums[m] = 0

while True:

p += 1

if nums[p]:

break

return [n for n in nums[2:] if n]

And after about an hour this is what I got. It's a good bit slower but I think it's because of the j function which is what "marks of multiples of p".

- Code: Select all
`def j(f): f[1][f[0]] = 0`

def p1(upper):

return (lambda q:[z for z in (lambda h:[map((lambda x: None if not x[1] else map(lambda l: j(l),[(t,h) for t in range(x[1]*2,len(x[0]),x[1])])), [(h,s) for s in h[2:int(int(len(h)**0.5)+1)]]),h][1])(range(q))[2:] if z])(upper)