Skip to content

Instantly share code, notes, and snippets.

@yuheiomori
Created April 24, 2012 21:25
Show Gist options
  • Save yuheiomori/2483939 to your computer and use it in GitHub Desktop.
Save yuheiomori/2483939 to your computer and use it in GitHub Desktop.
codeeval Sum of Primes
from itertools import count, islice
def is_prime(n):
return not any(n % i == 0 for i in range(2, n / 2 + 1))
def prime_generator():
for candidate in count(2):
if (is_prime(candidate)):
yield candidate
if __name__ == "__main__":
print sum(islice(prime_generator(), 1000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment