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%201 | |
| //K.A | |
| object problem01 { | |
| def getMtp(mn : Int) : Int = { | |
| Range(1, mn).toList.filter(i => i % 3 == 0 || i % 5 == 0).sum | |
| } | |
| def main(args : Array[String]) { | |
| val mn = 1000 | |
| println(getMtp(mn)) |
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%202 | |
| //K.A | |
| object problem02 { | |
| def fbnEvnSum(mn : Int) : BigInt = { | |
| lazy val fbn: Stream[Int] = 0 #:: fbn.scanLeft(1)(_+_).takeWhile(_ <= mn) | |
| fbn.filter(_ % 2 == 0).sum | |
| } | |
| def main(args : Array[String]) { | |
| val mn = 4000000 |
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%203 | |
| //K.A | |
| import scala.math._ | |
| object problem03 { | |
| def getMaxPfc(tn : Long) : Int = { | |
| val pr = 2 #:: Stream.from(3) | |
| pr.filter(i=> pr.takeWhile(j=> pow(j, 2) <= i).forall(i % _ > 0)).takeWhile(_ <= sqrt(tn)).filter(tn % _ == 0).max | |
| } |
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%204 | |
| //K.A | |
| import scala.math._ | |
| object problem04 { | |
| def getPldNum(dig : Int) : Int = { | |
| val minNum : Int = 1 * pow(10,(dig - 1)).toInt | |
| val maxNum : Int = (1 * pow(10, dig)).toInt - 1 | |
| (minNum to maxNum).flatMap(i => (i to maxNum).map(_ * i)).filter(n => n.toString == n.toString.reverse).max |
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%205 | |
| //K.A | |
| object problem05 { | |
| def getDivMin(sl : List[Int]) : Int = { | |
| Range(sl.last, Int.MaxValue).takeWhile(i=> !sl.forall(i % _ == 0)).max + 1 | |
| } | |
| def main(args : Array[String]) { | |
| val sl = (1 to 20).toList | |
| println(getDivMin(sl)) |
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%2050 | |
| //K.A | |
| import scala.math._ | |
| object problem50 { | |
| def getPrimeSumMax(mn : Long) : Long = { | |
| lazy val pr : Stream[Int] = 2 #:: Stream.from(3).filter(i => pr.takeWhile(j => pow(j,2) <= i).forall(i % _ > 0)).takeWhile(_ <= mn) | |
| val pr2 = pr.takeWhile(i => pr.takeWhile(_ <= i).map(_.toLong).sum <= mn) | |
| for (i <- pr2.length to 1 by -1) { |
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%2023 | |
| //K.A | |
| object problem23 { | |
| def getNoAbdNum(mn : Int) : Int = { | |
| val an = (0 to mn).map(i => Range(1, i).filter(i % _ == 0).sum).zipWithIndex.filter(j => j._1 > j._2).map(_._2) | |
| val on = an.flatMap(i => an.takeWhile(_ <= mn).map(_ + i)) | |
| (1 to mn).diff(on).sum | |
| } |
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%2012 | |
| //K.A | |
| import scala.math._ | |
| object problem12 { | |
| def getTrgFst(mn : Int) : Int = { | |
| lazy val tn: Stream[Int] = 1 #:: Stream.from(2).scanLeft(1)(_+_) | |
| def divCnt(tn: Int) = (0 to Int.MaxValue -1).takeWhile(i => pow(i, 2) <= tn).reduceLeft((l, r) => if(tn % r == 0) l + 2 else l) |
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%2015 | |
| //K.A | |
| object problem15 { | |
| def getRootCnt(n: Int, k: Int): BigInt = { | |
| (BigInt(1) to n).product/(BigInt(1) to k).product.pow(2) | |
| } | |
| def main(args : Array[String]) { | |
| val mCnt = 20 | |
| println(getRootCnt(mCnt*2, mCnt)) |
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%2029 | |
| //K.A | |
| object problem29 { | |
| def getDtntSize(min: Int, max: Int): Int = { | |
| (min to max).map(i => (BigInt(min) to max).map(j=> j.pow(i))).reduceLeft(_ ++ _).distinct.size | |
| } | |
| def main(args : Array[String]) { | |
| val min = 2 | |
| val max = 100 |