Created
December 11, 2012 22:54
-
-
Save dschobel/4263101 to your computer and use it in GitHub Desktop.
sieve of eratosthenes in scala
This file contains 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
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