Last active
January 2, 2016 16:09
-
-
Save jlandahl/8327971 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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