Created
November 18, 2012 05:19
-
-
Save kazua/4103745 to your computer and use it in GitHub Desktop.
Project Euler Problem 10
This file contains hidden or 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
| //http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2010 | |
| //K.A | |
| import scala.math._ | |
| object problem10 { | |
| def getSumPrime(max : Int) : Long = { | |
| lazy val pr : Stream[Int] = 2 #:: Stream.from(3).filter(i=> pr.takeWhile(j=> pow(j, 2) <= i).forall(i % _ > 0)).takeWhile(_ < max) | |
| pr.map(_.toLong).reduceLeft(_+_) | |
| } | |
| def main(args : Array[String]) { | |
| val max = 2000000 | |
| val gsp = getSumPrime _ | |
| println(gsp(max)) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment