Created
November 9, 2012 17:40
-
-
Save bgreenlee/4047063 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes in Scala #scala #algorithms
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
# sieve of eratosthenes | |
def sieve(s: Stream[Int]): Stream[Int] = s.head #:: sieve(s.tail filter (_ % s.head != 0)) | |
def from(n: Int): Stream[Int] = n #:: from(n + 1) | |
def primes = sieve(from(2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment