Skip to content

Instantly share code, notes, and snippets.

@andlima
Created October 1, 2011 21:25
Show Gist options
  • Select an option

  • Save andlima/1256678 to your computer and use it in GitHub Desktop.

Select an option

Save andlima/1256678 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes in Python
def primes(maximum):
discarded = set()
was_discarded = discarded.__contains__
discard_all = discarded.update
limit = maximum + 1
yield 2
for m in xrange(3, limit, 2):
if not was_discarded(m):
yield m
discard_all(xrange(m * 2, limit, m))
@mpereira

mpereira commented Oct 1, 2011

Copy link
Copy Markdown

How does it compare with mongodb?

@andlima

andlima commented Oct 1, 2011

Copy link
Copy Markdown
Author

Let's say this is not exactly web scale. :c)

@andlima

andlima commented Oct 1, 2011

Copy link
Copy Markdown
Author

BTW, "web scale" this: https://gist.github.com/1256699 :c)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment