For those who wish a lot more challenge then the old Spanish alphabetical order, let's take a look at how the Hungarian alphabet is ordered.
a, á, b, c, cs, d, dz, dzs, e, é, f, g, gy, h, i, í, j, k, l, ly, m, n, ny, o, ó, ö, ő, p, q, r, s, sz, t, ty, u, ú, ü, ű, v, w, x, y, z, zs
actually, q
, w
, x
and y
are not used in Hungarian words, but they are included for loanwords and foreign names. Foreign accented characters which are not part of the Hungarian alphabet (like ñ
), have the same priority as the non-accented ones, but we disregard them for this challenge.
The rules, summarized:
- Digraphs (
cs
,sz
, etc.) and the trigraph (dzs
) are considered as they were letters on their own.
cudar cukor cuppant csalit csata
- If the same digraph or trigraph occurs twice directly after each other in a word, they are written in a simplified way:
ssz
instead ofszsz
,ddzs
instead ofdzsdzs
but for the alphabetical order the non-simplified order is used. For examplekasza
<kaszinó
<kassza
, becausekassza
is used ask
+a
+sz
+sz
+a
for the sake of ordering. Sometimes you can find the non-contracted version in a word, in case of compound words.
kasza kaszinó kassza kaszt nagy naggyá nagygyakorlat naggyal nagyít
- capitalization doesn't matter, with the exception when the two words would be exactly the same without capitalization, in which case the lower case letter has priority
jácint Jácint Zoltán zongora
- The short and long versions of accented vowels have the same priority (
a - á
,e -é
,i - í
,o - ó
,ö - ő
,u - ú
ü - ű
), with a single exception: if the two words would otherwise be exactly the same, the short vowel has priority over the long vowel. Note, that the vowels with umlaut (ö
andü
) are completely different characters fromo
andu
.
Eger egér író iroda irónia kerek kerék kérek szúr szül
- Hyphens or spaces (for example, in compound words, names, etc.) are completely ignored
márvány márványkő márvány sírkő Márvány-tenger márványtömb
The task
Your program/function receives strings, composed of characters from the Hungarian alphabet (both lower- and upper-case), but a string might contain spaces or hyphens. For simplicity's sake, the minus sign (ASCII 45) can be used as a hyphen. Note that some characters (like the ő
) are not part of ASCII. You can use any encoding you wish, if it supports all the required characters.
You have to order the lines correctly and display/return the result.
You can use any randomly ordered subset of the above examples for testing.
EDIT:
Please don't use any built-in or other way which already knows the Hungarian alphabetical ordering by itself. It would make the competition pointless, and take all the challenge from finding the best regular expression or the best code golfing tricks.
EDIT2:
To clear a clarification asked by isaacg: "two strings that only differ by capitalization and long vs. short vowels, but differs in both ways" : Although no rule in the official document explicitly addresses this question, an example found within points to the length of the vowel having more importance than the capitalization.
malacsült
ornyílászáró
. I wonder if there are any (but you'd need a vocabulary to check for that, which is presumably not part of this challenge) \$\endgroup\$