Skip to content

Instantly share code, notes, and snippets.

@odwrotnie
Created March 23, 2014 10:52
Show Gist options
  • Save odwrotnie/9721554 to your computer and use it in GitHub Desktop.
Save odwrotnie/9721554 to your computer and use it in GitHub Desktop.
val primes = {
def sieve(nums: Stream[Int]): Stream[Int] =
Stream.cons(nums.head, sieve((nums.tail) filter (_ % nums.head != 0)))
sieve(Stream.from(2, 1))
}
println(primes.take(1000).mkString(", "))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment