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%2035 | |
| //K.A | |
| object problem35 { | |
| lazy val pr : Stream[Int] = 2 #:: Stream.from(3).filter(i => pr.takeWhile(j => BigInt(j).pow(2) <= i).forall(i % _ > 0)).takeWhile(_ <= 1000000) | |
| def isPrime(i : Int) = { | |
| if (i < 2) false | |
| else (2 until i).exists(i % _ == 0) == false | |
| } | |
| def problem35 = pr.filter(i => (List(0, 2, 4, 5, 6, 8).forall(j => i.toString.indexOf(j.toString) == -1) || i.toString.length == 1) && (1 until i.toString.length).map(n => i.toString.drop(n) + i.toString.take(n)).forall(k => isPrime(k.toInt) == true)).size |
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%2038 | |
| //K.A | |
| object problem38 { | |
| def problem38 = (1 to 9999).map(i => (1 to 9).map(j => (1 to j).map(k => i * k).mkString)).flatten.filter(n => n.length == 9 && (1 to 9).map(m => n.indexOf(m.toString)).forall(_ >= 0)).max | |
| def main(args : Array[String]) { | |
| println(problem38) | |
| } | |
| } |
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%2036 | |
| //K.A | |
| object problem36 { | |
| def problem36 = (1 until 1000000).filter(i => i.toString == i.toString.reverse && i.toBinaryString == i.toBinaryString.reverse).sum | |
| def main(args : Array[String]) { | |
| println(problem36) | |
| } | |
| } |
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%2039 | |
| //K.A | |
| object problem39 { | |
| def problem39 = (3 to 1000).map(i => for (b <- 2 until i; a <- 1 until b; c = i - a - b if a * a + b * b == c * c && c > 0) yield List(i, a, b, c)).filter(_ != Nil).map(n => List(n.head.head, n.size)).sortBy(s => s.last).last.head | |
| def main(args : Array[String]) { | |
| println(problem39) | |
| } | |
| } |
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%2063 | |
| //K.A | |
| import scala.math._ | |
| object problem63 { | |
| def problem63 = (1 until 10).map(i => (log(10D) / log(10D / i)).toInt).sum | |
| def main(args : Array[String]) { | |
| println(problem63) | |
| } |
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%2055 | |
| //K.A | |
| object problem55 { | |
| def bolLychrel(nm : BigInt, acl : Int) : Boolean = nm match { | |
| case a if (a + BigInt(a.toString.reverse)).toString == (a + BigInt(a.toString.reverse)).toString.reverse => false | |
| case a => if (acl < 50) bolLychrel(a + BigInt(a.toString.reverse), acl + 1) else true | |
| } | |
| def problem55 = (1 until 10000).map(i => bolLychrel(i, 0)).filter(_ == true).size | |
| 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%2017 | |
| //K.A | |
| object problem17 { | |
| val u20 = List(0, 3, 3, 5, 4, 4, 3, 5, 5, 4, 3, 6, 6, 8, 8, 7, 7, 9, 8, 8) | |
| val t10 = List(0, 0, 6, 6, 5, 5, 5, 7, 6, 6) | |
| def calcChrLen(nm : Int, acl : Int) : Int = nm match { | |
| case a if a < 20 => acl + (if (acl > 0 && a > 0) 3 else 0) + u20(a) | |
| case a if a < 100 => calcChrLen(a % 10, acl + t10(a / 10)) | |
| case a if a < 1000 => calcChrLen(a % 100, acl + u20(a / 100) + 7) |
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%2027 | |
| //K.A | |
| import scala.collection.mutable._ | |
| import scala.math._ | |
| object problem27 { | |
| lazy val pr : Stream[Int] = 2 #:: Stream.from(3).filter(i => pr.takeWhile(j => pow(j, 2) <= i).forall(i % _ > 0)).takeWhile(_ < 1000) | |
| val memo = Map[Int, Boolean]() | |
| def isPrime(n : Int) = if (n < 2) |
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%2097 | |
| //K.A | |
| object problem97 { | |
| def problem97 = (28433 * (BigInt(1) << 7830457) + 1) % BigInt(10).pow(10) | |
| def main(args : Array[String]) { | |
| println(problem97) | |
| } | |
| } |
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
| import scala.math._ | |
| object perfectnum { | |
| def getPfnList(mn : Int) : Seq[BigInt] = { | |
| lazy val pr : Stream[Int] = 2 #:: Stream.from(3).filter(i => pr.takeWhile(j => pow(j, 2) <= i).forall(i % _ > 0)).takeWhile(_ <= sqrt(mn * 2)) | |
| (1 to sqrt(mn * 2).toInt).map(i => (BigInt(1) << i) - 1).filter(pr.contains).map(j => j * (j + 1) / 2) | |
| } | |
| def main(args : Array[String]) { | |
| val mn = 100000000 |