Skip to content

Instantly share code, notes, and snippets.

@kazua
Created November 19, 2013 21:08
Show Gist options
  • Save kazua/7552620 to your computer and use it in GitHub Desktop.
Save kazua/7552620 to your computer and use it in GitHub Desktop.
Project Euler Problem 112(PHP)
<?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);
gc_collect_cycles();
return $r;
}
function problem112($i = 538, $b = 269) {
for (; $b / $i * 100 < 99; $i++) if (ckBouncy($i)) $b++;
return $i;
}
echo problem112();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment