Skip to content

Instantly share code, notes, and snippets.

@trendsetter37
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trendsetter37/8db44ffc43bfa54d3d47 to your computer and use it in GitHub Desktop.
Save trendsetter37/8db44ffc43bfa54d3d47 to your computer and use it in GitHub Desktop.
Kind of a hack for the CodeEval reverse and add problem in php
<?php
/** Recursive calls should be kept to under 100 per problem prompt.
* Or else this would not work in PHP */
function iter_palindrome($integer, $count = 0) {
$reverse_int = strrev($integer);
if (intval($reverse_int) == intval($integer)) {
echo $count . " ";
echo $integer . "\n";
return;
} else {
$count++;
$sum = intval($integer) + intval($reverse_int);
iter_palindrome(strval($sum), $count);
}
}
$fh = fopen($argv[1], "r");
while (true) {
$test = fgets($fh);
if (!$test) {
break;
}
iter_palindrome($test);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment