Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.