Skip to content

Instantly share code, notes, and snippets.

@dschobel
Created December 11, 2012 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dschobel/4263101 to your computer and use it in GitHub Desktop.
Save dschobel/4263101 to your computer and use it in GitHub Desktop.
sieve of eratosthenes in scala
def from(n: Int): Stream[Int] = n #:: from(n+1)
def sieve(nums: Stream[Int]): Stream[Int] = nums.head #:: sieve(nums.tail.filterNot(_ % nums.head == 0))
def primes: Stream[Int] = sieve(from(2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment