Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active May 26, 2020 15:22
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/427f83bfce81bc3eb1bdc166a29adcf2 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/427f83bfce81bc3eb1bdc166a29adcf2 to your computer and use it in GitHub Desktop.
Just PHP FUN 007.

Just PHP FUN 007.

Started at 26.05.2020 21:12 Tuesday May.
Finished at 26.05.2020 22:22 Tuesday May. (1hr 10 minutes).

<?php
# https://www.codewars.com/kata/5aa1bcda373c2eb596000112 Maximum Triplet Sum (Array Series #7).
function maxTriSum($nums) {
sort($nums);
return array_sum(array_slice(array_unique($nums),-3));
}
<?php
# https://www.codewars.com/kata/5af15a37de4c7f223e00012d Sort Out The Men From Boys.
function menFromBoys($arr) {
$man = array_filter($arr, function($x){ return 0 == abs($x)%2;});
sort($man);
$boys = array_filter($arr, function($x){ return 1 == abs($x)%2;});
rsort($boys);
$answer = array_unique(array_merge($man, $boys));
return array_values($answer);
}
<?php
# https://www.codewars.com/kata/5ac6932b2f317b96980000ca Form The Minimum.
function minValue($arr) {
sort($arr);
return intval(implode(array_unique($arr)));
}
<?php
# https://www.codewars.com/kata/5ae7e3f068e6445bc8000046 See You Next Happy Year. `count_chars`
function nextHappyYear($year) {
$year += 1;
$separate = function($x){
$x = str_split(strval($x));
$new_size = count(array_unique($x));
return 4 == $new_size;
};
while(!$separate($year)) $year += 1;
return $year;
}
<?php
# https://www.codewars.com/kata/5abd66a5ccfd1130b30000a9 Row Weights.
function rowWeights($arr) {
$one = 0; $two = 0;
foreach( $arr as $i=>$x){
if(0 == $i%2){ $one += $x; }
else { $two += $x;}
}
return [$one, $two];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment