Skip to content

Instantly share code, notes, and snippets.

@kazua
Created November 17, 2012 09:03
Show Gist options
  • Save kazua/4094396 to your computer and use it in GitHub Desktop.
Save kazua/4094396 to your computer and use it in GitHub Desktop.
Project Euler Problem 07
//http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%207
//K.A
import scala.math._
object problem07 {
def getPrime(cnt : Int) : Int = {
val pr = 2 #:: Stream.from(3)
pr.filter(i=> pr.takeWhile(j=> pow(j, 2) <= i).forall(i % _ > 0))(cnt - 1)
}
def main(args : Array[String]) {
val cnt = 10001
val gpc = getPrime _
println(gpc(cnt))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment