Last active
December 10, 2015 05:29
-
-
Save kazua/4388453 to your computer and use it in GitHub Desktop.
Project Euler Problem 46
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%2046 | |
| //K.A | |
| import scala.math._ | |
| object problem46 { | |
| def getOddCmpsNumMin() : Int = { | |
| lazy val pr : Stream[Int] = 2 #:: Stream.from(3).filter(i => pr.takeWhile(j => BigInt(j).pow(2) <= i).forall(i % _ > 0)) | |
| val or : Stream[Int] = Stream.from(2).filter(_ % 2 != 0).filter(i => pr.takeWhile(_ <= i).forall(_ != i)) | |
| val ormin : Stream[Int] = or.dropWhile(i => pr.takeWhile(_ <= i).map(j => sqrt((i - j)/2)).forall(k => ceil(k) != floor(k)) == false) | |
| ormin.take(1).min | |
| } | |
| def main(args : Array[String]) { | |
| println(getOddCmpsNumMin()) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment