Created
January 26, 2011 16:02
-
-
Save velociraptors/796909 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
LIMIT = 20001 | |
NATURALS = range(3,LIMIT, 2) | |
PRIMES = [2] | |
current = 0 | |
max = LIMIT | |
while len(NATURALS) > 0: | |
current = NATURALS.pop(0) | |
PRIMES.append(current) | |
i = current | |
try: | |
max = NATURALS[-1] | |
except IndexError: | |
break | |
while i <= max: | |
i = i + current | |
try: | |
NATURALS.remove(i) | |
except ValueError: | |
pass | |
print('primes: {0}'.format(PRIMES)) | |
print('sum: {0}'.format(sum(PRIMES))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LIMIT = 2000001
NATURALS = range(3,LIMIT, 2)
PRIMES = [2]
current = 0
while len(NATURALS) > 0:
current = NATURALS.pop(0)
PRIMES.append(current)
try:
n = NATURALS[-1] / current
except IndexError:
pass
i = current
while n > 1:
i = n * current
try:
NATURALS.remove(i)
except ValueError:
pass
n -= 1
print('sum: {0}'.format(sum(PRIMES)))