Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active July 8, 2020 16:05
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/7d97b6809dbe819c99747604ffa1351b to your computer and use it in GitHub Desktop.
Save lbvf50mobile/7d97b6809dbe819c99747604ffa1351b to your computer and use it in GitHub Desktop.
Just PHP FUN 044.
<?php
# https://www.codewars.com/kata/581b30af1ef8ee6aea0015b9 Find how many times did a team from a given country win the Champions League?
function countWins($winnerList, $country) {
$x = array_count_values(array_map(function($x){ return $x['country'];},$winnerList));
return isset($x[$country]) ? $x[$country] : 0;
}
<?php
# https://www.codewars.com/kata/5834315e06f227a6ac000099 Find twins.
function elimination($arr){
$x = array_count_values($arr);
foreach($x as $k=>$v) if(2 == $v) return $k;
return null;
}
<?php
# https://www.codewars.com/kata/595877be60d17855980013d3 Euclidean distance in n dimensions.
function euclidean_distance(array $a, array $b): float {
return round(sqrt(array_sum(array_map(function($x,$y){ return abs($x-$y)**2;},$a,$b))),2);
}
<?php
# https://www.codewars.com/kata/58dabca7ce77a12dbd00000f Highest power of 2 that evenly divides a number.
function solution(int $n): int {
for($i = 1; 0 == $n%$i ; $i *= 2);
return $i/2;
}

Just PHP FUN 044.

Started at 22:31 at 08.07.2020 Wednesday July.
Finished at 23:04 at 08.07.2020 Wednesday July. (0hrs 33minutes)

<?php
# https://www.codewars.com/kata/5925acf31a9825d616000e74 Friday the 13th Part 1.
function killcount($z, $zz){
return array_column(array_filter($z,function($x) use ($zz){ return $x[1] < $zz;}),0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment