Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active July 16, 2020 16:08
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/aadc3fe820e890ac705e7723e26820e8 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/aadc3fe820e890ac705e7723e26820e8 to your computer and use it in GitHub Desktop.
Just PHP FUN 051.
<?php
# https://www.codewars.com/kata/58846b46f4456a8919000025 Simple Fun #16: Apple Boxes.
function apple_boxes(int $k): int {
for($i = 1, $diff = 0; $i <= $k; $i += 1) $diff += ($i*$i)*((-1)**$i);
return $diff;
}
<?php
# https://www.codewars.com/kata/58c8e1c2a7f31af03600008f Reflection in PHP #1 - Introduction.
function get_info($fn) {
$x = new ReflectionFunction($fn);
$answer = [];
$answer[] = $x->getNumberOfParameters();
$answer[] = $x->getNumberOfRequiredParameters();
$answer[] = $x->hasReturnType();
$answer[] = $x->isClosure();
$answer[] = $x->isInternal();
$answer[] = $x->isUserDefined();
return $answer;
}

Just PHP FUN 051.

Started at 20:32 16.07.2020 Thursday July.
Finished at 22:46 16.07.2020 Thursday July. (2hrs 14minutes)

<?php
# https://www.codewars.com/kata/58846b46f4456a8919000025 Simple Fun #13: Magical Well.
function magical_well($a, $b, $n) {
for($i = 0, $sum = 0; $i < $n; $i += 1){ $sum += $a*$b; $a += 1; $b += 1;}
return $sum;
}
<?php
function increment_x(){ $GLOBALS['x'] += 1; }
function double_x_triple_y_quadruple_z(){ global $x, $y, $z; $x *= 2; $y *= 3; $z *= 4;}
function append_whitespace_to_string(){ global $string; $string .= " ";}
function add_world_to_string(){ global $string; $string .= "world";}
<?php
# https://www.codewars.com/kata/57d3c6a043942a34d200015e PHP Functions - Splat Operator.
function sum_all(...$x){ return array_sum($x);}
function ultimate_product(...$x){return array_product($x);}
function scale_sum(...$x){ return $x[0]*array_sum(array_slice($x,1));}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment