Created
January 27, 2010 13:32
-
-
Save bongole/287830 to your computer and use it in GitHub Desktop.
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
// Sieve of Eratosthenes | |
def calc_primes( nums:List[Int] ):List[Int] = { | |
nums match { | |
case x::xs => | |
val nums_dash = for( i <- xs if i % x != 0 ) yield i | |
println( Runtime.getRuntime.totalMemory/1024/1024 ) | |
x :: calc_primes( nums_dash ) | |
case _ => Nil | |
} | |
} | |
val res = calc_primes( (2 to 100000).toList ) // java.lang.OutOfMemoryError: Java heap space | |
println( res.size ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment