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%2022 | |
| //K.A | |
| import java.io._ | |
| import scala.io.Source | |
| object problem22 { | |
| def sum(acl : Int, s : String) : Int = s match { | |
| case null => acl | |
| case "" => acl |
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%206 | |
| //K.A | |
| import scala.math._ | |
| object problem06 { | |
| def sum(acl : Long, xs : List[Int]) : Long = xs match { | |
| case Nil => acl | |
| case y :: ys => sum(acl + pow(y,2).toLong, ys) | |
| } |
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%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) | |
| } |
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%208 | |
| //K.A | |
| object problem08 { | |
| def calcSliceProduct(nums : String) : Int ={ | |
| if (!nums.forall(_.isDigit)){ | |
| println("数字でない文字がまじっています。") | |
| 0 | |
| }else{ | |
| nums.map(_.asDigit).sliding(5).map(_.product).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%209 | |
| //K.A | |
| import scala.math._ | |
| object problem09 { | |
| def pythagoras(mc : Int) : Int = { | |
| val pg = for (b <- 2 until mc; a <- 1 until b; c = mc - (a + b) if pow(a, 2) + pow(b, 2) == pow(c, 2)) yield a * b * c | |
| pg.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%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(_+_) | |
| } |
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%2013 | |
| //K.A | |
| object problem13 { | |
| def calcSliceSum(nums : String) : String = { | |
| if (!nums.forall(_.isDigit)) { | |
| "数字でない文字がまじっています。" | |
| } else { | |
| nums.sliding(50,50).map(_.take(11).toLong).sum.toString.take(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%2016 | |
| //K.A | |
| import scala.math._ | |
| object problem16 { | |
| def getMtPNum(mp : Int) : String = { | |
| BigInt(2).pow(mp).toString.map(_.asDigit).sum.toString | |
| } | |
| 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%2048 | |
| //K.A | |
| import scala.math._ | |
| object problem48 { | |
| def getMtpSum(mn : Int) : String = { | |
| (1 to mn).map(i => BigInt(i).pow(i)).reduceLeft(_+_).toString.takeRight(10) | |
| } | |
| 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%2019 | |
| //K.A | |
| object problem19 { | |
| def getSunCnt : Int = { | |
| val dayCnt = List(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) | |
| def mlf(st : Int, ed : Int) = for(y <- st to ed; m <- 1 to 12) yield if (if (m != 2 || (m == 2 && ((y % 100 == 0 && y % 400 != 0) || (y % 4 != 0)))) false else true) 29 else dayCnt(m - 1) | |
| val ml1900 = mlf(1900,1900) | |
| val ml = mlf(1901,2000) |