Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active June 16, 2020 15:49
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/0b507154b029aa98a2e0319dc72e63c0 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/0b507154b029aa98a2e0319dc72e63c0 to your computer and use it in GitHub Desktop.
Just PHP FUN 025.
<?php
# https://www.codewars.com/kata/5a4138acf28b82aa43000117 Maximum Product.
function adjacentElementsProduct($a) {
$max = $a[0]*$a[1];
for($i = 2; $i < count($a); $i += 1) if($max < $a[$i-1]*$a[$i]) $max = $a[$i] * $a[$i-1];
return $max;
}
<?php
# https://www.codewars.com/kata/586a1af1c66d18ad81000134 Driving Licence.
function driver($data) {
$a = str_pad(substr($data[2],0,5),5,9);
$b = substr($data[3],-2,1);
$date = strtotime($data[3]);
$c = date('m',$date);
$c = $data[4] == "M" ? $c : intval($c) + 50;
echo "Month; $c \n";
$d = date('d',$date);
echo "The date: $d \n";
$e = substr($data[3],-1);
echo "The year digit: $e \n";
$f = str_pad(substr($data[0],0,1).substr($data[1],0,1),2,9);
echo "Initials: $f \n";
$ans = strtoupper("$a$b$c$d$e{$f}9AA");
return $ans;
}
<?php
# https://www.codewars.com/kata/5b180e9fedaa564a7000009a Fix string case.
function solve($s) {
$big = preg_match_all('/[A-Z]/',$s);
return $big > strlen($s) - $big ? strtoupper($s) : strtolower($s);
}
#-----------------------------------------------------------------------
function solve($s) {
$big = []; $small = [];
preg_match_all('/[A-Z]/',$s,$big); preg_match_all('/[a-z]/',$s,$small);
if(count($small[0]) >= count($big[0])) return strtolower($s);
return strtoupper($s);
}

Just PHP FUN 025.

Started at 20:09 16.06.2020 Tuesday June.
Finished at 22:48 16.06.2020 Tuesday June. (2hrs 39minutes)

<?php
# https://www.codewars.com/kata/59d9ff9f7905dfeed50000b0 Alphabet symmetry.
function solve($arr) {
$counter = function($x){
$sum = 0; $x = str_split(strtolower($x));
foreach($x as $i=>$v) if(ord($v)+1 - ord('a') == $i + 1) $sum += 1;
return $sum;
};
return array_map($counter, $arr);
}
<?php
# https://www.codewars.com/kata/5ce969ab07d4b7002dcaa7a1 String prefix and suffix.
function solve($s) {
$max = 0; $bound = strlen($s)/2 - 1;
for($i = 0; $i <= $bound; $i += 1){
$a = substr($s,0,$i+1);
$b = substr($s,-($i+1));
if( $a == $b ) $max = $i + 1;
}
return $max;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment