- https://www.codewars.com/kata/559536379512a64472000053 Playing with passphrases.
Started at 23:58 27.10.2020 Tuesday Oct.
Finished at 22:01 28.10.2020 Wendesday Oct. (22hrs 3 minutes)
Started at 23:58 27.10.2020 Tuesday Oct.
Finished at 22:01 28.10.2020 Wendesday Oct. (22hrs 3 minutes)
<?php | |
# https://www.codewars.com/kata/559536379512a64472000053 Playing with passphrases. | |
function playPass($s, $n) { | |
$s = str_split($s); | |
$s = array_map(function($x) use ($n){ | |
if(preg_match('/[A-Z]/',$x)){ | |
return char($x,$n); | |
} | |
if(preg_match('/[0-9]/',$x)){ | |
return digit($x); | |
} | |
return $x; | |
},$s); | |
for($i = 0; $i < count($s); $i += 1) if(1 == $i%2) $s[$i] = strtolower($s[$i]); | |
return strrev(implode($s)); | |
} | |
function char($c,$n){ | |
return chr( ((ord($c) + $n - ord("A"))%(ord("Z")-ord("A")+1)) + ord("A")); | |
} | |
function digit($c){ | |
$ans = strval(9 - intval($c)); | |
return $ans; | |
} |