Created
April 24, 2012 21:25
-
-
Save yuheiomori/2483939 to your computer and use it in GitHub Desktop.
codeeval Sum of Primes
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
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