Skip to content

Instantly share code, notes, and snippets.

@bongole
Created January 27, 2010 13:32
Show Gist options
  • Save bongole/287830 to your computer and use it in GitHub Desktop.
Save bongole/287830 to your computer and use it in GitHub Desktop.
// 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