Skip to content

Instantly share code, notes, and snippets.

@daclouds
Created June 2, 2013 01:30
Show Gist options
  • Save daclouds/67b184fdb1b1a36bd181 to your computer and use it in GitHub Desktop.
Save daclouds/67b184fdb1b1a36bd181 to your computer and use it in GitHub Desktop.
object Euler7 extends App {
val primes = 2 #:: isPrime(3)
def isPrime(n: Int) : Stream[Int] =
if (primes.takeWhile(p => p*p <= n).exists(n % _ == 0)) isPrime(n + 2)
else n #:: isPrime(n + 2)
println(primes(10000))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment