Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active July 13, 2020 17:03
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/b02b1cdb571eb4cc5eb6eb2ba8b932d2 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/b02b1cdb571eb4cc5eb6eb2ba8b932d2 to your computer and use it in GitHub Desktop.
Just PHP FUN 048.
<?php
# https://www.codewars.com/kata/59000d6c13b00151720000d5 Simple Fun #215: Properly Closed Bracket Word.
function closed_bracket_word(string $word): bool {
$x = range(ord('a'),ord('z')); $y = array_reverse($x);
$z = array_combine($x,$y);
$w = array_map('ord',str_split($word));
$w = array_map(null,$w,array_reverse($w));
foreach($w as $v) if($z[$v[0]] != $v[1]) return false;
return true;
}
<?php
# https://www.codewars.com/kata/58d8f800a1111a80f400021a Statistics 101: Coin Sampling.
function sample($coin) {
for($i = 0, $x = 0; $i < 1000000; $i++) if($coin()) $x += 1;
echo "$x \n";
return $x/1000000;
}
<?php
# https://www.codewars.com/kata/58f6024e1e26ec376900004f Find Factors Down to Limit.
function factors(int $integer, int $limit): array {
for($i = $limit, $a = []; $i <= $integer; $i ++) if (0 == $integer%$i) array_push($a, $i);
return $a;
}
<?php
# https://www.codewars.com/kata/58bcd27b7288983803000002 Simple Fun #182: Happy "g"
function g_happy(string $str): bool {
$x = [];
preg_match_all('/g+/',$str,$x);
$x = array_filter(array_map('strlen',$x[0]),function($x){ return $x == 1;});
if(empty($x)) return true;
return false;
}

Just PHP FUN 048.

Started at 22:39 13.07.2020 Monday July.
Finished at 0:02 14.07.2020 Tuesday July. (1hr 23minutes)

<?php
# https://www.codewars.com/kata/58fd91af13b0012e8e000010 Simple Fun #203: Strange Coach.
function strangeCoach($players){
$ans = [];
foreach(array_count_values(array_map(function($x){ return $x[0];},$players)) as $k=>$v)
if($v >= 5) array_push($ans,$k);
if(empty($ans)) return "forfeit";
sort($ans);
return implode($ans);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment