Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active June 11, 2020 12:51
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/d2c926c4c7f43917512ef7ec49163f70 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/d2c926c4c7f43917512ef7ec49163f70 to your computer and use it in GitHub Desktop.
Just PHP FUN 021.
<?php
# https://www.codewars.com/kata/580dda86c40fa6c45f00028a Sum of Odd Cubed Numbers.
function cube_odd($a) {
$answer = 0;
foreach($a as $v){
if(!is_numeric($v)) return NULL;
if(0 != abs($v**3)%2) $answer += $v**3;
}
return $answer;
}

Just PHP FUN 021.

Started at 11.06.2020 17:43 Thurdday June.
Finishd at 11.06.2020 19:50 Thursday June. (2hrs 7 minutes)

<?php
# https://www.codewars.com/kata/562f91ff6a8b77dfe900006e Going to the cinema.
function movie($c, $t, $pr) {
$a = 0;
$b = $c;
for($i = 1; ceil($b) >= $a; $i++){
$a += $t;
$b += $t * pow($pr,$i);
//echo "$i a=$a b=$b \n";
}
return $i-1;
}
<?php
# https://www.codewars.com/kata/58f6f87a55d759439b000073 Negation of a Value.
function negationValue($str, $val) {
return 1 == strlen($str)%2 ? ! $val : $val;
}
<?php
# https://www.codewars.com/kata/56541980fa08ab47a0000040 Printer Errors.
function printerError($s) {
return intval(preg_match_all('/[^a-m]/',$s))."/".strlen($s);
}
<?php
# https://www.codewars.com/kata/57f22b0f1b5432ff09001cab Well of Ideas - Harder Version.
function well($arr)
{
$sum = 0;
array_walk_recursive($arr,function($x) use(&$sum){
if('good' == strtolower($x)) $sum += 1;
});
if( 0 >= $sum) return 'Fail!';
if(2 >= $sum ) return 'Publish!';
return 'I smell a series!';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment