Skip to content

Instantly share code, notes, and snippets.

@jarsen
Created December 12, 2012 01:25
Show Gist options
  • Save jarsen/4264045 to your computer and use it in GitHub Desktop.
Save jarsen/4264045 to your computer and use it in GitHub Desktop.
The sieve of Eratosthenes.
sieve = (n) ->
primes = (true for i in [3..n])
for i in [2..n]
continue if Math.pow(i,i) > n
for j in [Math.pow(i,i)-3..n] by i
primes[j] = no
(index + 3 for primality, index in primes when primality)
console.log sieve(1000000)
@jarsen
Copy link
Author

jarsen commented Dec 12, 2012

wat. why is gist indenting that for.

@ryanflorence
Copy link

tabs? in coffeescript? what is wrong with you?

@jarsen
Copy link
Author

jarsen commented May 15, 2013

i don't know what i'm doing, florence. it's an experiment.

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