Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active June 29, 2020 16:29
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/d445db77504c3e3460ea207c68f051f8 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/d445db77504c3e3460ea207c68f051f8 to your computer and use it in GitHub Desktop.
Just PHP FUN 036.
<?php
# https://www.codewars.com/kata/56b97b776ffcea598a0006f2 Bubblesort Once.
function bubblesort_once($a) {
for($i = 1; $i < count($a); $i++){
if( $a[$i-1] > $a[$i]) {
$tmp = $a[$i];
$a[$i] = $a[$i-1];
$a[$i-1] = $tmp;
}
}
return $a;
}
<?php
# https://www.codewars.com/kata/52b5247074ea613a09000164 Boiled Eggs.
function cooking_time(int $eggs): int {
return ceil($eggs/8)*5;
}

Just PHP FUN 036.

Started at 29.06.2020 22:05 Monday June.
Finised at 29.06.2020 23:29 Monday June. (1hr 24 minutes)

<?php
# https://www.codewars.com/kata/5b4f8e02578c6aae9700008b Round To Nearest.
class RoundToNearest
{
public static function roundUp(int $number, array $list): array
{
if(empty($list)) return [];
$tmp = array_map(function($x) use ($number){ return abs($x - $number);}, $list);
$min = min($tmp);
$ans = array_values(array_filter($list,function($x) use ($min,$number){ return abs($x - $number) == $min;}));
return $ans;
}
}
<?php
# https://www.codewars.com/kata/594a1822a2db9e93bd0001d4 Simple Fun #320: Scratch lottery I.
function (array $lottery): int {
$x = array_map(function($x){
$x = array_values(array_unique(explode(" ",$x)));
if(count($x) == 2) return $x[1];
return 0;
},$lottery);
return array_sum($x);
}
<?php
# https://www.codewars.com/kata/58a6841442fd72aeb4000080 Simple Fun #138: Similarity.
function similarity(array $a, array $b): float {
return count(array_intersect($a,$b))/count(array_unique(array_merge($a,$b)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment