Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active September 14, 2020 14:25
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 lbvf50mobile/75dd65467a2d31fe2387f170fb3f887b to your computer and use it in GitHub Desktop.
Save lbvf50mobile/75dd65467a2d31fe2387f170fb3f887b to your computer and use it in GitHub Desktop.
Just PHP FUN 102.
<?php
# https://www.codewars.com/kata/58e09234ca6895c7b300008c Numerical Palindrome #1.5.
function palindrome($num, $s) {
$n = "Not valid";
if( (!is_int($num)) || (!is_int($s))) return $n;
if( 0 > $num || 0 > $s) return $n;
$counter = 0;
$answer = [];
while($counter < $s){
if(check($num)){
array_push($answer,$num);
$counter += 1;
}
$num += 1;
}
return $answer;
}
function check($x){
$a = strval($x);
$b = strrev($a);
return $a == $b && 1 < strlen($a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment