Created
October 31, 2010 12:32
-
-
Save v6ak/656538 to your computer and use it in GitHub Desktop.
No řekněte sami, kdo z vás tohle má? Scala rulez! Functional programming rulez!
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 Application{ | |
| def sieve(s:Stream[Int]):Stream[Int] = Stream.cons(s.head, sieve(s.tail.filter(_%s.head != 0))) // Sieve of Eratosthenes | |
| val primes = sieve(Stream from 2) // Stream of all primes | |
| primes take 10 foreach println // print first 10 primes | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment