Last active
December 17, 2015 14:59
-
-
Save amarvutha/5628301 to your computer and use it in GitHub Desktop.
Prime testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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