Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active July 14, 2020 18:53
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/010c6f81f5f963025877911c1c8fa2bf to your computer and use it in GitHub Desktop.
Save lbvf50mobile/010c6f81f5f963025877911c1c8fa2bf to your computer and use it in GitHub Desktop.
Just PHP FUN 049.
<?php
# https://www.codewars.com/kata/582746fa14b3892727000c4f Coding Meetup #1 - Higher-Order Functions Series - Count the number of JavaScript developers coming from Europe.
function count_developers($a) {
return count(
array_filter($a,
function($x){ return "Europe" == $x["continent"] && "JavaScript" == $x["language"];})
);
}
<?php
# https://www.codewars.com/kata/588431bb76933b84520000d3 Simple Fun #6: Is Infinite Process?
function is_infinite_process(int $a, int $b): bool {
return $a > $b || ($a < $b && 1 == ($b - $a)%2);
}

Just PHP FUN 049.

Started at 22:07 14.07.2020 Tuesday July.
Finished at 1:52 15.07.2020 Wednesday July. (3hr 45minues)

<?php
# https://www.codewars.com/kata/58842a2b4e8efb92b7000080 Simple Fun #5: Knapsack Light.
function knapsack_light(int $v1, int $w1, int $v2, int $w2, int $mw): int {
if($w1 + $w2 <= $mw) return $v1+$v2;
if($w1 <= $mw && $w2 <= $mw) return max($v1,$v2);
if($w1 <= $mw) return $v1;
if($w2 <= $mw) return $v2;
return 0;
}
<?php
# https://www.codewars.com/kata/58bcdc65f6d3b11fce000045 Simple Fun #184: LCM from m to n.
function mn_lcm(int $m, int $n): int {
$a = min($m,$n); $b = max($m,$n);
$x = $a;
// echo "$a $b start \n";
for($i = $a+1; $i <= $b; $i+=1) {
// echo "1. $i and $x $x%$i = ".($x%$i)."\n";
$delta = $x;
while(0 != $x%$i) $x += $delta;
// echo "2. $i and $x $x%$i = ".($x%$i)."\n";
}
return $x;
}
<?php
# https://www.codewars.com/kata/58bccdf56f25ff6b6d00002f Simple Fun #181: Rounding.
function rounding($n,$m){
$a = $m * ceil($n/$m);
$b = $m * floor($n/$m);
$x = 5;
if(abs($n-$a) == abs($n-$b)) return $n;
if(abs($n-$a) < abs($n-$b)){ $x = (int) $a;}
else{ $x = (int) $b;}
return $x;
}
<?php
# https://www.codewars.com/kata/57e0e52c8a8b8dfa6c0000b7 PHP in Action #2 - HTTP GET Method [Fundamentals].
// Define the correct key-value pairs here
function user_script(){
global $avocado, $banana, $dragonfruit;
extract(array_map('htmlspecialchars',$_GET));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment