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
| package euler.zerosum | |
| object Euler0014 { | |
| def main(args: Array[String]) { | |
| println( | |
| (1 until 1000000).map(x => solveCollatz(x, x, 0)).maxBy(_._2)._1 | |
| ) | |
| } | |
| def solveCollatz(i: Long, tmp: Long, counter: Long): (Long, Long) = { |
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
| package euler.zerosum | |
| object Euler0015 { | |
| def main(args: Array[String]) { | |
| val width = args(0).toInt | |
| val height = args(1).toInt | |
| val numer = width + 1 to width + height | |
| val denom = 1 to height |
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
| package euler.zerosum | |
| object Euler0011 { | |
| def main(args: Array[String]) { | |
| val horizontal = take4ElemsEvery(1, given, Nil) | |
| val vertical = take4ElemsEvery(21, given, Nil) | |
| val diagonal = take4ElemsEvery(20, given, Nil) ::: take4ElemsEvery(22, given, Nil) | |
| val products = (horizontal ++ vertical ++ diagonal).map(_.product) |
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
| package euler.zerosum | |
| object Euler0012 { | |
| // 数xの因数iは、x = i^2 の場合を除き、対となる因数i'が存在する。 | |
| // √xを超えない自然数に含まれるxの因数の個数をnとするとき、 | |
| // xの全ての因数の個数は2nもしくは2n+1個である。 | |
| def main(args: Array[String]) { | |
| println(getTriangle(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
| package euler.zerosum | |
| object Euler0024 { | |
| def main(args: Array[String]) { | |
| println(getArrangement(999999, (0 to 9).toList, Nil).mkString) | |
| } | |
| private def getArrangement(order: Int, objects: List[Int], arrangement: List[Int]): List[Int] = { | |
| val unit = fact(objects.length - 1, 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
| package euler.zerosum | |
| object Euler0023 { | |
| def main(args: Array[String]) { | |
| val limit = 28123 | |
| val numbers = from(1).take(limit) | |
| val abundant = getAbundant(limit) | |
| println(numbers.filterNot(x => isSumOfTwoElems(x, abundant.takeWhile(_ <= x))).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
| package euler.zerosum | |
| object Euler0028 { | |
| def main(args: Array[String]) { | |
| println(getCorner(3, 1001, from(1).take(1)).sum) | |
| } | |
| private def getCorner(width: Int, maxWidth: Int, corners: Stream[Int]): Stream[Int] = { | |
| val maxValue: Int = maxWidth * maxWidth |
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
| package euler.zerosum | |
| import euler.zerosum.Divisors._ | |
| import euler.zerosum.Number._ | |
| object Euler0021 { | |
| def main(args: Array[String]) { | |
| println(from(1).take(9999).filter(hasAmicable(_)).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
| package euler.zerosum | |
| import io.Source | |
| object Euler0022 { | |
| def main(args: Array[String]) { | |
| val f = Source.fromFile("names.txt") // via. http://projecteuler.net/project/names.txt | |
| println(namesScore(f.mkString.split(',').toList.map(_.filterNot(_ == '"')).sortWith(_<_))) | |
| f.close() |
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
| package euler.zerosum | |
| object Euler0032 { | |
| /** | |
| * [1..9]の順列によって得られる9桁の数を2箇所で区切って得られるx,y,zの3数が | |
| * x*y=zをみたす桁数の組み合わせ(digit(x), digit(y), digit(z))は | |
| * {(1, 4, 4), (2, 3, 4)}のいずれか | |
| * | |
| * (∵) | |
| * 1桁*3桁、2桁*2桁の演算は高々4桁、また、 |