Created
July 5, 2011 11:52
-
-
Save dcsobral/1064703 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes One-Liner
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
(n: Int) => (2 to n) |> (r => r.foldLeft(r.toSet)((ps, x) => if (ps(x)) ps -- (x * x to n by x) else ps)) | |
// Forward-pipe courtesy of Scalaz, or look here: http://stevegilham.blogspot.com/2009/01/pipe-operator-in-scala.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment