Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active June 27, 2020 16:16
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/26d4b22c6f8d756724f6d839eea634f5 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/26d4b22c6f8d756724f6d839eea634f5 to your computer and use it in GitHub Desktop.
Just PHP FUN 035.
<?php
# https://www.codewars.com/kata/57ee24e17b45eff6d6000164 Cat and Mouse - Easy Version.
function cat_mouse(string $s): string {
$x = count_chars($s);
if( $x[ord('.')] <= 3) return "Caught!";
return "Escaped!";
}
<?php
# https://www.codewars.com/kata/5866e6992e8d9cdbcd00040a All Star Code Challenge #28.
function convert_c_f(...$x) {
list($num,$scale) = $x;
echo "$num $scale \n";
if($scale && !in_array($scale,['c','f'])) throw new InvalidArgumentException();
if('f' == $scale) {$ans = ($num * 9/5) + 32;}
else {$ans = ($num - 32) * 5/9;}
echo "ans = $ans \n";
return $ans;
}
<?php
# https://www.codewars.com/kata/57cf3dad05c186ba22000348 Resistor Color Codes.
function decodeResistorColors($bands) {
$map = ['black'=> 0, 'brown'=> 1, 'red' => 2,
'orange' => 3, 'yellow' => 4, 'green' => 5, 'blue' => 6, 'violet' => 7, 'gray' => 8, 'white' => 9,
'gold' => 5, 'silver' => 10, 'none' => 20];
$x = explode(" ",$bands);
if(3 == count($x)) array_push($x,'none');
$r = ($map[$x[0]]*10 + $map[$x[1]]) * (10 ** $map[$x[2]]);
$tlr = $map[$x[3]];
if( 1000000 <= $r) { $r = ($r/(10**6))."M";}
else if (1000 <= $r) {$r = ($r/(10**3))."k";}
else { $r = $r;}
return "$r ohms, $tlr%";
}

Just PHP FUN 035.

Started at 21:56 27.06.2020 Saturday June.
Finished at 23:15 27.06.2020 Saturday June. (1hr 19minutes)

<?php
# https://www.codewars.com/kata/588425ee4e8efb583d000088 Simple Fun #4: Phone Call.
function phone_call(int $min1, int $min2_10, int $min11, int $s): int {
if($s < $min1) return 0;
if($min1 <= $s && $s <= $min1 + $min2_10*9) return ($s - $min1)/$min2_10 + 1;
return ($s - ($min1 + $min2_10*9) )/$min11 + 10;
}
<?php
# https://www.codewars.com/kata/5864e2c473bd9c67b70002ba All Star Code Challenge #13.
function translate(string $s): string {
if(strlen($s) < 2) return $s;
if(preg_match('/^[^aeiou]/',$s)) $s = preg_replace('/^(.)(.+)/','$2$1',$s);
return $s."ay";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment