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
| <?php | |
| //array_reduceLeftとarray_reduceRight | |
| //write kazua | |
| //array_reduceLeft | |
| //$a:array 入力の配列 | |
| //$f:callback => mixed callback ( mixed &$result , mixed $item ) | |
| //$i イニシャル値 | |
| function array_reduceLeft(array $a, callable $f, $i = null) { | |
| $r = $i; |
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
| <?php | |
| //http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%208 | |
| //write kazua | |
| function problem008() { | |
| for ($a = 1; $a < 1000; $a++) | |
| for ($b = $a + 1; $b < 1000 - $a; $b++) | |
| if (pow($a, 2) + pow($b, 2) == pow(1000 - $a - $b, 2)) | |
| return ($a * $b * (1000 - $a - $b)); | |
| } |
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%20113 | |
| //write kazua | |
| import scala.math._ | |
| object problem113 { | |
| def problem113d(n : Int, k : Int, i : Int = 1, r : BigInt = BigInt(0)) : BigInt = r match { | |
| case r if r == BigInt(0) => problem113d(n, min(k, n - k), i, BigInt(1)) | |
| case _ => { | |
| i match { |
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%20112 | |
| //write kazua | |
| object problem112another { | |
| def ckBouncy(n : Int) = n.toString.toList.sortWith(_ < _).mkString.toInt != n && n.toString.toList.sortWith(_ > _).mkString.toInt != n | |
| def problem112(i : Int = 538, b : Int = 269) : Int = (b.toDouble / i.toDouble * 100).toInt match { | |
| case n if n < 99 => if (ckBouncy(i)) problem112(i + 1, b + 1) else problem112(i + 1, b) | |
| case n => i | |
| } | |
| 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
| <?php | |
| //http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%20112 | |
| //write kazua | |
| function ckBouncy($n) { | |
| if (strspn($n, "0123456789") != strlen($n)) return false; | |
| $k = $z = $g = str_split($n); | |
| sort($z); | |
| rsort($g); | |
| $r = ($k != $z) && ($k != $g); | |
| unset($k,$z,$g); |
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%20112 | |
| //write kazua | |
| object problem112 { | |
| def ckBouncy(n : Int, k : Int = -1, z : Boolean = false, g : Boolean = false) : Boolean = k match { | |
| case k if k == 0 => (z && g) | |
| case k if k < 0 => ckBouncy(n % 10, n / 10) | |
| case k => { | |
| val x = k % 10 | |
| if (x < n) ckBouncy(x, k / 10, true, g) |
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
| <?php | |
| //http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2030 | |
| //write kazua | |
| for ($i = 2; $i < pow(9, 5) * 5; $i++) | |
| if (array_sum( | |
| array_map( | |
| function ($value) { | |
| return pow($value, 5); | |
| }, str_split($i))) === $i) | |
| $a[] = $i; |
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%20120 | |
| //write kazua | |
| object problem120 { | |
| def problem120 = (3 to 1000).map(i => 2 * i * ((i - 1) / 2)).sum | |
| def main(args : Array[String]) { | |
| println(problem120) | |
| } | |
| } |
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
| <?php | |
| //http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2025 | |
| //write kazua | |
| for ($a = array(1 => "1", "1"), $i = 3; strlen($a[$i - 1]) < 1000; $i++) | |
| $a[$i] = bcadd($a[$i - 2], $a[$i - 1]); | |
| echo ($i - 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
| <?php | |
| //http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%207 | |
| //write kazua | |
| $p = array(); | |
| $i = 2; | |
| $f = function ($value) { | |
| global $p; | |
| $a = range(1, (int) sqrt($value)); |