Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active July 24, 2020 16:44
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/b0f369b39fa56bd1cf72d08f6c00f9be to your computer and use it in GitHub Desktop.
Save lbvf50mobile/b0f369b39fa56bd1cf72d08f6c00f9be to your computer and use it in GitHub Desktop.
Just PHP FUN 058.
<?php
# https://www.codewars.com/kata/585c284d06512958820001a6 Emily's Eccentric Encoding.
function decode($string){
$small = array_combine ( range('a','z') , array_reverse(range('a','z')) );
$string = preg_replace_callback('/[a-z]/', function($x) use ($small) { return $small[$x[0]];},$string);
return $string;
}
<?php
# https://www.codewars.com/kata/5857e8bb9948644aa1000246 Can Santa save Christmas?
function determine_time(array $durations): bool {
$sec = function($x){
list($h,$m,$s) = explode(":",$x);
$value = intval($s) + intval($m)*60 + intval($h)*60*60;
return $value;
};
$total = array_sum(array_map($sec,$durations));
$all = 60*60*24;
return $total <= 60*60*24;
}

Just PHP FUN 058.

Started at 22:29 24.07.2020 Friday July.
Finished at 23:43 24.07.2020 Friday July. (1hr 14minutes)

<?php
# https://www.codewars.com/kata/57029e77005264a3b9000eb5 Nothing special.
function nothing_special($s): string {
if(! is_string($s)) return "Not a string!";
return preg_replace('/[^a-z0-9\s]/i','',$s);
}
<?php
# https://www.codewars.com/kata/57e90bcc97a0592126000064 Holiday V - SeaSick Snorkelling.
function sea_sick(string $s): string {
$size = strlen($s); $chng = 0;
for($i = 1; $i < $size; $i++) if($s[$i-1] != $s[$i]) $chng += 1;
return $chng*100/$size > 20 ? "Throw Up": "No Problem";
}
<?php
# https://www.codewars.com/kata/585eaef9851516fcae00004d Naughty or Nice?
function what_list_am_i_on(array $actions): string {
$evaluation = array_reduce(
$actions,
function($acc, $x){
$value = preg_match('/^[gsn]/',$x) ? 1 : (preg_match('/^[bfk]/',$x) ? -1 : 0);
return $acc + $value;
},
0
);
return $evaluation > 0 ? 'nice' : 'naughty';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment