Created
June 21, 2014 11:55
-
-
Save jhedev/5172301ffa53bdc5dc7a to your computer and use it in GitHub Desktop.
Python primes
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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
import itertools | |
def gen(i): | |
while True: | |
yield i | |
i = i + 1 | |
def primes(gen): | |
p = next(gen) | |
yield p | |
def g(): | |
for i in gen: | |
if i % p > 0: | |
yield i | |
for i in primes(g()): | |
yield i | |
def prime(x): | |
return next(itertools.islice(primes(gen(2)), x, x+1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment