Skip to content

Instantly share code, notes, and snippets.

@jlandahl
Last active January 2, 2016 16:09
Show Gist options
  • Save jlandahl/8327971 to your computer and use it in GitHub Desktop.
Save jlandahl/8327971 to your computer and use it in GitHub Desktop.
object Primes extends App {
val primes: Stream[Int] =
2 #:: Stream.from(3, 2).filter(i => primes.takeWhile(p => p * p <= i).forall(p => i % p > 0))
println(primes.take(10).toList) // List(2, 3, 5, 7, 11, 13, 17, 19, 23, 29)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment