Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active June 3, 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/99e45ac3f3cdb26d1cfdde2890146fdd to your computer and use it in GitHub Desktop.
Save lbvf50mobile/99e45ac3f3cdb26d1cfdde2890146fdd to your computer and use it in GitHub Desktop.
Just PHP FUN 014.
<?php
# https://www.codewars.com/kata/56747fd5cb988479af000028 Get the Middle Character.
function ($text) {
$last = strlen($text) - 1;
if(0 == $last%2) return substr($text,$last/2,1);
return substr($text, floor($last/2),2);
}
<?php
# https://www.codewars.com/kata/57eba158e8ca2c8aba0002a0 Sort by Last Char.
function last($x)
{
$array = explode(" ",$x);
$cmp = function($a,$b){
$a1 = substr(strrev($a),0,1);
$b1 = substr(strrev($b),0,1);
if($a1 == $b1) return 0;
if($a1 > $b1) return 1;
return - 1;
};
usort($array,$cmp);
return $array;
}
<?php
# https://www.codewars.com/kata/57e8f757085f7c7d6300009a Holiday II - Plane Seating.
function planeSeat($a){
$char = preg_replace('/[0-9]+/',"",$a);
$number = (int) preg_replace('/[A-Z]/',"",$a);
echo "char = ($char) number = ($number)\n";
if(60 < $number) return "No Seat!!";
if("I" == $char || "J" == $char || "K" < $char || "" == $char) return "No Seat!!";
$x = "";
if("A" <= $char && $char <= "C") $x = "Left";
if("D" <= $char && $char <= "F") $x = "Middle";
if("G" <= $char && $char <= "K") $x = "Right";
$y = "";
if(1 <= $number && $number <= "20") $y = "Front";
if(21 <= $number && $number <= "40") $y = "Middle";
if(40 <= $number && $number <= "60") $y = "Back";
return "$y-$x";
}
<?php
# https://www.codewars.com/kata/57ebaa8f7b45ef590c00000c Numbers to Letters.
function switcher($arr)
{
$map = function($x){
if( 1 <= $x && $x <= 26) return chr(ord('a') + 26 - $x);
if( '27' == $x) return "!";
if( '28' == $x) return "?";
if( 29 == $x) return " ";
};
return implode(array_map($map,$arr));
}
<?php
# https://www.codewars.com/kata/5868812b15f0057e05000001 Tail Swap.
function tail_swap(array $a): array {
list($a0,$b0) = explode(":",$a[0]);
list($a1,$b1) = explode(":",$a[1]);
return [ $a0.":".$b1, $a1.":".$b0];
}
@lbvf50mobile
Copy link
Author

@lbvf50mobile
Copy link
Author

$alphabet = array_reverse(range("a", "z"));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment