Skip to content

Instantly share code, notes, and snippets.

@belushkin
Last active September 26, 2018 16:24
Show Gist options
  • Save belushkin/b1d49ab482413780cf9682ccdda610e5 to your computer and use it in GitHub Desktop.
Save belushkin/b1d49ab482413780cf9682ccdda610e5 to your computer and use it in GitHub Desktop.
Sum of Digit is Pallindrome or not
<?php
function isPalindrome(String $n)
{
if (strlen($n) == 1) {
return $n;
} else {
$res = $n[0] + isPalindrome(substr($n, 1));
}
$res = (string)$res;
for ($i = 0; $i < strlen($res); $i++) {
if ($res[$i] != $res[strlen($res)-$i-1]) {
return 'NO';
}
}
return 'YES';
}
$n = 56;
echo isPalindrome($n);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment