Skip to content

Instantly share code, notes, and snippets.

@amarvutha
Last active December 17, 2015 14:59
Show Gist options
  • Save amarvutha/5628301 to your computer and use it in GitHub Desktop.
Save amarvutha/5628301 to your computer and use it in GitHub Desktop.
Prime testing
def test2(x):
""" Sieve of Eratosthenes """
p = []
mask = range(2,x-1)
while len(mask)>0:
p.append(mask[0])
del mask[::p[-1]]
return p
def test1(x):
""" Naive testing by divisibility """
p = [2,3,5,7]
for i in xrange(7,x-1):
isprime = True
for pi in p:
isprime = ( isprime and (i%pi) )
if not isprime: break
if isprime: p.append(i)
return p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment