Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active May 25, 2020 17:19
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/fca81bf04f03aca82f3643f906fec164 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/fca81bf04f03aca82f3643f906fec164 to your computer and use it in GitHub Desktop.
Just PHP FUN 006.
<?php
# https://www.codewars.com/kata/5a662a02e626c54e87000123 Extra Perfect Numbers (Special Numbers Series #7).
function extraPerfect($n) {
$answer = [];
for($i = 1; $i <= $n; $i++){
$tmp = decbin($i);
if("1" == substr($tmp,0,1) && "1" == substr($tmp,-1,1)) array_push($answer,$i);
}
return $answer;
}

Just PHP FUN 006.

Started at 25.05.2020 Monday May 21:40.
Finished at 20.05.2020 Monday May 22:29. (0hrs 50 minutes)

<?php
# https://www.codewars.com/kata/5aba780a6a176b029800041c Maximum Multiple.
function maxMultiple($divisor, $bound) {
return $bound - $bound%$divisor;
}
<?php
# https://www.codewars.com/kata/563b662a59afc2b5120000c6 Growth of a Population.
function nbYear($p0, $percent, $aug, $p) {
$year = 0;
while($p0 < $p){
$p0 = $p0 + $p0*$percent*0.01 + $aug;
$year += 1;
}
return $year;
}
<?php
# https://www.codewars.com/kata/5bd776533a7e2720c40000e5 The Poet And The Pendulum.
function pendulum($values) {
$answer = [ ]; sort($values);
$size = count($values);
for($i = 0; $i < $size; $i++){
if(0 == $i%2){
array_unshift($answer,$values[$i]);
}else{
array_push($answer, $values[$i]);
}
}
return $answer;
}
<?php
# https://www.codewars.com/kata/51f2d1cafc9c0f745c00037d String ends with?
function solution($str, $ending) {
if(empty($ending))
return true;
return substr($str,-(strlen($ending))) == $ending;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment