Skip to content

Instantly share code, notes, and snippets.

@v6ak
Created October 31, 2010 12:32
Show Gist options
  • Select an option

  • Save v6ak/656538 to your computer and use it in GitHub Desktop.

Select an option

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!
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