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%2025 | |
| //K.A | |
| object problem025 { | |
| def getFbnDgtFst(dc : Int) : BigInt = { | |
| lazy val fbn: Stream[BigInt] = BigInt(0) #:: fbn.scanLeft(BigInt(1))(_+_).takeWhile(_.toString.length < dc) | |
| fbn.size | |
| } | |
| def main(args : Array[String]) { | |
| val dc = 1000 |
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%2026 | |
| //K.A | |
| object problem026 { | |
| def getRecDecMax(mn : Int) : Int = { | |
| val rd = (2 until mn).map(i => (1 until mn).dropWhile(BigInt(10).modPow(_, i) != 1)).map(k => k match { case a if a.isEmpty => 0 case a => a.min }) | |
| rd.indexOf(rd.max) + 2 | |
| } | |
| def main(args : Array[String]) { | |
| val mn = 1000 |
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%2018 | |
| //K.A | |
| object problem18 { | |
| val triangle = List(List(75), | |
| List(95, 64), | |
| List(17, 47, 82), | |
| List(18, 35, 87, 10), | |
| List(20, 04, 82, 47, 65), | |
| List(19, 01, 23, 75, 03, 34), |
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%2067 | |
| //K.A | |
| object problem67 { | |
| val triangle = List( | |
| List("59"), | |
| List("73", "41"), | |
| List("52", "40", "09"), | |
| List("26", "53", "06", "34"), | |
| List("10", "51", "87", "86", "81"), |
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%2030 | |
| //K.A | |
| object problem30 { | |
| def getMpNumEqNum(dc : Int) : Int = { | |
| val mc = (BigInt(10).pow((Stream.from(1).dropWhile(s => BigInt(10).pow(s) - 1 <= (BigInt(10).pow(s) - 1).toString.map(t => BigInt(t.toString).pow(dc)).sum)).take(1).min) - 1).toInt | |
| (2 to mc).filter(i => i.toString.map(j => BigInt(j.toString.toInt).pow(dc)).sum == i).sum | |
| } | |
| def main(args : Array[String]) { | |
| val dc = 5 |
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%2011 | |
| //K.A | |
| object problem11 { | |
| val square = List( | |
| List("08", "02", "22", "97", "38", "15", "00", "40", "00", "75", "04", "05", "07", "78", "52", "12", "50", "77", "91", "08"), | |
| List("49", "49", "99", "40", "17", "81", "18", "57", "60", "87", "17", "40", "98", "43", "69", "48", "04", "56", "62", "00"), | |
| List("81", "49", "31", "73", "55", "79", "14", "29", "93", "71", "40", "67", "53", "88", "30", "03", "49", "13", "36", "65"), | |
| List("52", "70", "95", "23", "04", "60", "11", "42", "69", "24", "68", "56", "01", "32", "56", "71", "37", "02", "36", "91"), | |
| List("22", "31", "16", "71", "51", "67", "63", "89", "41", "92", "36", "54", "22", "40", "40", "28", "66", "33", "13", "80"), |
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%2014 | |
| //K.A | |
| object problem14 { | |
| def getCollatzDgt(nm : Long, acl : Int) : Int = nm match { | |
| case a if a == 1 => acl + 1 | |
| case a => { | |
| val nn = if (nm % 2 == 0) nm / 2 else (3 * nm) + 1 | |
| getCollatzDgt(nn, acl + 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%2034 | |
| //K.A | |
| object problem34 { | |
| def getLimited(dc : Int) : Int = dc match { | |
| case a if ((1 to 9).product * a < (BigInt(10).pow(a + 1) - 1)) => (BigInt(10).pow(a + 1)).toInt - 1 | |
| case a => getLimited(dc + 1) | |
| } | |
| def getFactSumEq() : Int = { | |
| (0 to getLimited(1)).map(_.toString.toList).map(_.map(c => (1 to c.asDigit).product).sum).zipWithIndex.filter(t => t._1 == t._2).map(_._1).sum - 3 |
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%2032 | |
| //K.A | |
| object problem32 { | |
| def problem32 = (1 to 99).map(i => if (i < 10) (1000 to 9999).map(j => List(i, j, (i * j))) | |
| else (100 to 999).map(j => List(i, j, (i * j))) | |
| ).flatten.filter(_.mkString.length == 9) | |
| .filter(k => (1 to 9).map(m => k.mkString.indexOf(m.toString)).forall(n => n >= 0)) | |
| .map(_.last).distinct.sum | |
| def main(args : Array[String]) { |
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%2037 | |
| //K.A | |
| object problem37 { | |
| def isPrime(i : Int) = { | |
| if (i < 2) false | |
| else (2 until i).exists(i % _ == 0) == false | |
| } | |
| def getRPrime(pl : List[Int], acl : List[Int]) : List[Int] = pl match { | |
| case a if a.size == 0 => acl.reverse |