Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active May 29, 2020 15:06
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/b07264f3b8328c89516e4ea66c4a4aee to your computer and use it in GitHub Desktop.
Save lbvf50mobile/b07264f3b8328c89516e4ea66c4a4aee to your computer and use it in GitHub Desktop.
Just PHP FUN 010.
<?php
# https://www.codewars.com/kata/5a58d889880385c2f40000aa Automorphic Number (Special Numbers Series #6).
function automorphic($n) {
if($n == substr($n*$n,- strlen($n))) return "Automorphic";
return "Not!!";
}
<?php
# https://www.codewars.com/kata/5a53a17bfd56cb9c14000003 Disarium Number (Special Numbers Series #3).
function calc($n){
$sum = 0;
$a = str_split($n);
foreach($a as $i=>$v){
$sum += pow($v,$i+1);
if($n < $sum) return false;
}
if($n != $sum) return false;
return true;
}
function disariumNumber($n) {
return calc($n) ? "Disarium !!" : "Not !!";
}

Just PHP FUN 010.

Started at 29.05.2020 21:10 Friday May.
Finished at 29.05.2020 22:06 Friday May. (0hrs 54minues)

<?php
# https://www.codewars.com/kata/5a63948acadebff56f000018 Product Of Maximums Of Array (Array Series #2).
function maxProduct($arr, $size) {
rsort($arr);
return array_product(array_slice($arr,0,$size));
}
<?php
# https://www.codewars.com/kata/5a55f04be6be383a50000187 Special Number (Special Numbers Series #5).
function specialNumber($n) {
return boolval(preg_match('/^[0-5]+$/',strval($n))) ? "Special!!" : "NOT!!";
}
<?php
# https://www.codewars.com/kata/5a87449ab1710171300000fd Tidy Number (Special Numbers Series #9).
function tidyNumber($n) {
$a = str_split($n);
for($i=1; $i<count($a); $i++)
if($a[$i-1] > $a[$i]) return false;
return true;
}
# -------------------------------------------
function tidyNumber($n) {
$n = str_split($n); $a = $n;
sort($a);
return $a == $n ? true : false;
}
# ------------------------------------------
function tidyNumber($n) {
$n = str_split($n); $a = $n;
sort($a);
return $a == $n;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment