Created
July 21, 2014 19:29
-
-
Save toshsan/2ff6a17c185e313c8a41 to your computer and use it in GitHub Desktop.
Python generator for N Prime number
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 primes(n): | |
yield 2 | |
primes=[2] | |
x = 1 | |
i = 3 | |
while(x<n): | |
isprime=True | |
for p in primes: | |
if i%p==0: isprime = False | |
if isprime: | |
primes.append(i) | |
yield i | |
x +=1 | |
i +=2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment