This challenge is based on, and contains test cases from, a programming course I took at Aalto University. The material is used with permission.
Two and a half years ago there was a challenge about spoonerisms in English. However, in Finnish spoonerisms are much more complicated.
Spoonerisms in Finnish
In Finnish, the vowels are aeiouyäö
and the consonants are bcdfghjklmnpqrstvwxz
. (å
is technically part of Finnish, but is not considered here.)
The most basic spoonerisms only take the first vowel of each word, and any consonants preceding them, and exchange the parts:
henri kontinen -> konri hentinen
tarja halonen -> harja talonen
frakki kontti -> kokki frantti
ovi kello -> kevi ollo
Long vowels
Some words contain two of the same consecutive vowel. In those cases, the vowel pair must be swapped with the other word's first vowel, shortening or lengthening vowels to keep the length same.
haamu kontti -> koomu hantti
kisko kaappi -> kasko kiippi
In the case of two different consecutive vowels this does not apply:
hauva kontti -> kouva hantti
puoskari kontti -> kooskari puntti
Three or more of the same consecutive letter will not appear in the input.
Vowel harmony
Finnish has this lovely thing called vowel harmony. Basically, it means that the back vowels aou
and front vowels äöy
should not appear in the same word.
When swapping front or back vowels into a word, all vowels of the other kind in the rest of the word should be changed to match the new beginning of the word (a <-> ä
, o <-> ö
, u <-> y
):
köyhä kontti -> kouha köntti
hauva läähättää -> läyvä haahattaa
e
and i
are neutral and may appear with all other letters; swapping them into a word must not cause changes to the rest of the word.
Special cases
Vowel harmony does not apply to some words, including many loan words and compound words. These cases are not required to be handled "correctly".
Challenge
Given two words, output the words spoonerised.
The input words will only contain the characters a-z
and äö
. You may choose to use uppercase or lowercase, but your choice must be consistent between both words and input/output.
I/O may be done in any convenient format. (Words should be considered strings or arrays of characters.)
This is code-golf, so the shortest solution in bytes wins.
Test cases
henri kontinen -> konri hentinen
tarja halonen -> harja talonen
frakki kontti -> kokki frantti
ovi kello -> kevi ollo
haamu kontti -> koomu hantti
hauva kontti -> kouva hantti
puoskari kontti -> kooskari puntti
köyhä kontti -> kouha köntti
hauva läähättää -> läyvä haahattaa
frakki stressi -> strekki frassi
äyskäri kontti -> kouskari äntti
hattu sfääri -> sfätty haari
ovi silmä -> sivi olma
haamu prätkä -> präämy hatka
puoskari sfääri -> sfäöskäri puuri
puoskari äyskäri -> äöskäri puuskari
uimapuku hajoa -> haimapuku ujoa
ihme baletti -> bahme iletti
uhka lima -> lihka uma
osuma makkara -> masuma okkara
makkara fakta -> fakkara makta
lapsi laiva -> lapsi laiva
firma hajoa -> harma fijoa
dimensio bitti -> bimensio ditti
flamingo joustava -> jomingo flaustava
globaali latomo -> labaali glotomo
trilogia fakta -> falogia trikta
printti maksa -> mantti priksa
riisi bitti -> biisi ritti
sini riisi -> rini siisi
aarre nyrkki -> nyyrre arkki
laavu laki -> laavu laki
kliininen parveke -> paaninen klirveke
priimus kahvi -> kaamus prihvi
spriinen lasta -> laanen sprista
kliimaksi mammona -> maamaksi klimmona
hylky hupsu -> hulku hypsy
kehys fiksu -> fihys keksu
levy huhu -> huvu lehu
tiheys guru -> guheus tiru
nyrkki heiluri -> herkki nyilyri
latomo hajoa -> hatomo lajoa
prisma lehti -> lesma prihti
viina baletti -> baana viletti
U+0308 COMBINING DIAERESIS
should handleU+00E4 LATIN SMALL LETTER A WITH DIAERESIS
just fine.) \$\endgroup\$e
andi
are neutral, arefihus keksy
,huvu lehy
andlesmä prihti
acceptable answers forkehys fiksu
,levy huhu
andprisma lehti
respectively? \$\endgroup\$puoskari äyskäri --> äöskäri puuskari --> puoskari ääskäri
. \$\endgroup\$