Regular Expression for Prime Numbers (or How I came to fail at them, and love the bomb)

cokofreedom at gmail.com cokofreedom at gmail.com
Thu Feb 14 03:33:05 EST 2008


> hmm... interesting
>
> here is another way you can find prime numbershttp://love-python.blogspot.com/2008/02/find-prime-number-upto-100-nu...
>

Sadly that is pretty slow though...

If you don't mind readability you can make the example I gave into
five lines.

def p(_):
 if _<3:return[2]if _==2 else[]
 a,b,b[1]=int(_**0.5)+1,range(_+1),0
 for c in xrange(2,a):
  if b[c]:b[c*c:_+1:c]=[0]*((_/c-c)+1)
 return[_ for _ in b if _]

But then, I would have to kill you...



More information about the Python-list mailing list