Skip to content

Instantly share code, notes, and snippets.

@jhedev
Created June 21, 2014 11:55
Show Gist options
  • Save jhedev/5172301ffa53bdc5dc7a to your computer and use it in GitHub Desktop.
Save jhedev/5172301ffa53bdc5dc7a to your computer and use it in GitHub Desktop.
Python primes
#!/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