Last active
August 29, 2015 14:11
-
-
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
This file contains 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 | |
/** 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