Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active September 7, 2020 16:06
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/f621029afac1f510163e0501c074fac8 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/f621029afac1f510163e0501c074fac8 to your computer and use it in GitHub Desktop.
Just PHP FUN 096.
<?php
# https://www.codewars.com/kata/58334362c5637ad0bb0001c2/ Filter valid romans.
function valid_romans($arr): array {
return array_values(array_filter($arr,'valid'));
}
function valid($s){
echo "Input: $s\n";
$units = '((IX)|(IV)|(VI{0,3})|(I{1,3})){0,1}';
$tens = '((XL)|(XC)|(LX{0,3})|(X{1,3})){0,1}';
$hdrds = '((CD)|(CM)|(DC{0,3})|(C{1,3})){0,1}';
$thsnds = '(M{1,4}){0,1}';
$regex = '/^('.$thsnds.$hdrds.$tens.$units.')$/';
echo "Regex: $regex\n";
var_dump(preg_match($regex,"MDLXXXVI"));
return (0 < strlen($s)) && (bool) preg_match($regex,$s);
}
<?php
# https://www.codewars.com/kata/58143221f9588e340e00009f/
function bangBang($history){
$x = explode("\n",$history);
$x = array_pop($x);
return preg_replace('/^\s+\d+\s+/',"",$x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment