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%2040 | |
| //K.A | |
| object problem40 { | |
| def getIrtlNumMlp(max: Int, irtNum: Seq[Int], acl: Int): Int = max match { | |
| case n if n < 1 => acl | |
| case n => getIrtlNumMlp(max / 10, irtNum, acl * irtNum(n - 1)) | |
| } | |
| def getMaxdgt(numdgt: Int, maxNumdgt: Int, maxNum: Int, acl: BigInt): BigInt = acl match { | |
| case n if n >= maxNum => (BigInt(10).pow(numdgt - 1)-1) - ((n - maxNum)/(numdgt - 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%2041 | |
| //K.A | |
| object problem41 { | |
| def isPrime(i : Int) = { | |
| if (i < 2) false | |
| else (2 until i).exists(i % _ == 0) == false | |
| } | |
| def getPandigitalPrime(nowNumdgt : Int, acl : Int) : Int = nowNumdgt match { | |
| case n if n == 2 || acl != 0 => 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%2043 | |
| //K.A | |
| object problem43 { | |
| def getPandigitalSum(maxNum : Int) : BigInt = { | |
| (0 to maxNum).permutations.map(_.mkString).filter(s => | |
| ((s.substring(0, 1).toInt != 0) && | |
| (s.substring(1, 4).toInt % 2 == 0) && | |
| (s.substring(2, 5).toInt % 3 == 0) && | |
| (s.substring(3, 6).toInt % 5 == 0) && |
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) |
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%2047 | |
| //K.A | |
| import scala.math._ | |
| object problem47 { | |
| def getConPfnFst(cnt : Int) : Int = { | |
| lazy val pr : Stream[Int] = 2 #:: Stream.from(3).filter(i=> pr.takeWhile(j=> BigInt(j).pow(2) <= i).forall(i % _ > 0)) | |
| Stream.from(2).dropWhile(i=> (0 until cnt).map(j => pr.take(ceil(sqrt(i+j)).toInt).filter((i+j) % _ == 0).size).forall(_ == cnt)==false).take(1).min | |
| } |
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
| //K.A | |
| //年の中に同じ数値が現れない年のリスト | |
| object yeardiff { | |
| def yeardiff(maxyear : Int) : Seq[String] = { | |
| (1 to maxyear).map(_.toString.toList).filter(a => a.distinct.size == a.size).map(_.mkString) | |
| } | |
| def main(args : Array[String]) { | |
| val nowyear = 2013 | |
| yeardiff(nowyear).foreach(println) |
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%2052 | |
| //K.A | |
| object problem52 { | |
| def getPosInt(mc : Int) : BigInt = { | |
| Stream.from(1).takeWhile(i => (2 to mc).map(j => (j * i).toString.toList).filter(_.diff(i.toString.toList).size > 0).isEmpty == false).max + 1 | |
| } | |
| def main(args : Array[String]) { | |
| println(getPosInt(6)) | |
| } |
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%2053 | |
| //K.A | |
| object problem53 { | |
| def getPascNum(lc : Int, mc : Int) : BigInt = { | |
| (1 to mc).map(i => (1 until mc).map(j => (BigInt(1) to i).product / ((BigInt(1) to j).product * (BigInt(1) to (i - j)).product)).filter(_ > lc).size).reduceLeft(_ + _) | |
| } | |
| def main(args : Array[String]) { | |
| val mCnt = 100 | |
| val lCnt = 1000000 |
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%2056 | |
| //K.A | |
| object problem56 { | |
| def getDigSumMax(mc : Int) : Int = { | |
| (1 until mc).map(i => (1 until mc).map(j => (BigInt(i).pow(j)).toString.toList.map(_.toString.toInt).sum)).reduceLeft(_ ++ _).max | |
| } | |
| def main(args : Array[String]) { | |
| val mCnt = 100 | |
| println(getDigSumMax(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%2024 | |
| //K.A | |
| object problem24 { | |
| def getPermNum(sn : String, cnt : Int) : String = { | |
| val bn = sn.toList.map(_.toString.toInt).filter(_ != 0).product | |
| sn.toList.permutations.filter(_.mkString.take(1) == (cnt / bn).toString).take(cnt % bn).map(_.mkString).toList.reverse.head | |
| } | |
| def main(args : Array[String]) { | |
| val cnt = 1000000 |