- https://www.codewars.com/kata/57fe5b7108d102fede00137a Hungarian Vowel Harmony (harder).
Started at 22:44 09.11.2020 Monday Nov.
Fnished at 23:21 10.11.2020 Tuesday Nov.
<?php | |
# https://www.codewars.com/kata/57fe5b7108d102fede00137a Hungarian Vowel Harmony (harder). | |
function instrumental(string $w): string { | |
$wp = [ | |
"a" => "á", | |
"e" => "é", | |
"i" => "í", | |
"o" => "ó", | |
"u" => "ú", | |
"ö" => "ő", | |
"ü" => "ű", | |
"á" => "á", | |
"é" => "é", | |
"í" => "í", | |
"ó" => "ó", | |
"ú" => "ú", | |
"ő" => "ő", | |
"ű" => "ű", | |
]; $x = strlen($w) - 1; | |
preg_match('/(.*)(.)$/u',$w, $matches); | |
$prefix = $matches[1]; | |
$last = $matches[2]; | |
if(preg_match('/[aáoóuú]$/',$w)){ | |
return $prefix. $wp[$last] . 'val'; | |
} | |
if(preg_match('/[eéiíöőüű]$/',$w)){ | |
return $prefix. $wp[$last] . 'vel'; | |
} | |
if(preg_match('/((sz)|(zs)|(cs))$/',$w)){ | |
preg_match('/(.*)(.)(.)(.)$/u',$w, $matches); | |
$l1 = $matches[4]; | |
$l2 = $matches[3]; | |
$l3 = $matches[2]; | |
$l4 = $matches[1]; | |
if(preg_match('/[aáoóuú]$/',$l3)){ | |
return $l4.$l3.$l2.$l2.$l1.'al'; | |
} | |
if(preg_match('/[eéiíöőüű]$/',$l3)){ | |
return $l4.$l3.$l2.$l2.$l1.'3l'; | |
} | |
} | |
if(preg_match('/[^aáoóuúeéiíöőüű]{2}$/',$w)){ | |
echo "$w \n"; | |
preg_match('/(.*)(.)(.)(.)$/u',$w, $matches); | |
$l1 = $matches[4]; | |
$l2 = $matches[3]; | |
$l3 = $matches[2]; | |
$l4 = $matches[1]; | |
if(preg_match('/[aáoóuú]$/',$l3)){ | |
$ans = $l4.$l3.$l2.$l1.$l1.'al'; | |
} | |
if(preg_match('/[eéiíöőüű]$/',$l3)){ | |
$ans = $l4.$l3.$l2.$l1.$l1.'el'; | |
} | |
echo "$ans \n"; | |
return $ans; | |
} | |
if(preg_match('/[aáoóuú].$/',$w)){ | |
preg_match('/(.*)(.)(.)$/u',$w, $matches); | |
$last = $matches[3]; | |
$prev = $matches[2]; | |
$prefix = $matches[1]; | |
return $prefix.$prev.$last.$last."al"; | |
} | |
if(preg_match('/[eéiíöőüű].$/',$w)){ | |
preg_match('/(.*)(.)(.)$/u',$w, $matches); | |
$last = $matches[3]; | |
$prev = $matches[2]; | |
$prefix = $matches[1]; | |
return $prefix.$prev.$last.$last."el"; | |
} | |
throw new Exception("Unhandled case. $w;"); | |
} |
Started at 22:44 09.11.2020 Monday Nov.
Fnished at 23:21 10.11.2020 Tuesday Nov.