Skip to content

Instantly share code, notes, and snippets.

@daiksy
Created November 21, 2012 07:25
Show Gist options
  • Save daiksy/4123577 to your computer and use it in GitHub Desktop.
Save daiksy/4123577 to your computer and use it in GitHub Desktop.
Project Euler Problem 7
/**
* http://projecteuler.net/problem=7
* http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%207
*/
val isPrime = (n: Int) => Iterator.from(2).takeWhile(p => p * p <= n).forall(p => n % p != 0)
def xs(n: Int): Stream[Int] = n #:: xs(n + 1)
val ret = xs(2).filter(isPrime).take(10001).last
println(ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment