Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sieve of Eratosthenes using Scala streams.
def sieve(s: Stream[Int]): Stream[Int] =
s.head #:: sieve(s.tail filter(_ % s.head != 0))
val primes = sieve(Stream.from(2))
primes.take(100).toList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.