Given a single string with a person's name and surname, output the first 6 characters of their codice fiscale.
Codice fiscale
Codice fiscale is a 16-character long alphanumeric string that identifies (almost uniquely) every Italian resident.
We are interested in the first six characters, which encode for surname and name, and are comprised of
- three letters for the surname/family name, obtained by concatenating (until three letters are reached):
- the surname's consonants in order
- the surname's vowels (
aeiou
) in order - the "
X
" character
- three letters for the given name(s), obtained by concatenating (until three letters are reached):
- the name's consonants in order
- but if there are four or more consonants, then the second is skipped (this exception doesn't apply to surnames)
- the name's vowels (
aeiou
) in order - the "
X
" character
- the name's consonants in order
For instance, the codice fiscale of Ms. Coding Challenges is CHLCNG
, while Dr. Code Golf has GLFCDO
, Sir Stack Exchange has XCHSCK
, and Mr. Nicola Sap has SPANCL
.
Note: although it's always pronounced as a vowel in Italian, y
is a consonant for the purposes of generating a codice fiscale.
Parsing the input
The input is a string made of ASCII alphabetic characters, spaces (
, at least one is guaranteed to be present), and possibly '
and -
s. It is assumed to be stripped (trimmed), and to not contain consecutive spaces (
). The challenge is case-insensitive, so you can choose to restrict inputs to only uppercase or only lowercase. Considered as a whole, both name and surname have at least two alphabetic letters (i.e. you won't need to append more than one X
per part).
To determine name and surname (that are both non-empty and are always given in this order), we will assume that:
- The last word (as defined by "
- If there are more than two words, and the last word did not contain
'
s or-
s, and the second-to-last word is two characters or less, then it is also part of the surname - All other words are part of the given name(s).
Some example name/surname separations:
Pinco Pallino Mario De Rossi Carla Lu Di Mare
--n-- ---s--- --n-- ---s---- ---n---- ---s---
Charlotte Oz D'Angelo Betta-Ty Verdi Alex Max Meucci
-----n------ ----s--- ----n--- --s-- ----n--- --s---
Output
Any reasonable output is valid: a string, two strings (surname code THEN name code), a list/array of characters. Case doesn't matter.
However, as opposed to the input, the surname code must come before the name code.
Examples and reference implementation
Some of these examples make it clear that the heuristic I developed to separate name from surname doesn't always work in the real world (Lea Rossi Del Bo's surname is "Rossi Del Bo" in real life, but it's "Bo" for the purpose of the challenge). You should follow the heuristic.
A-ha-ha Risolini , RSLHHA
Alex Max Meucci , MCCLMX
Betta-Ty Verdi , VRDBTT
Carla Lu Di Mare , DMRCLL
Code Golf , GLFCDO
Coding Challenges , CHLCNG
Charlotte Oz D'Angelo , DNGCRL
Dante Aligheri , LGHDNT
Dario Fo , FOXDRA
Ennio De Giorgi , DGRNNE
Filippo Brunelleschi , BRNFPP
Gaetana Aulenti , LNTGTN
Gerard 't Hooft , THFGRD
Giulietto Giulietti , GLTGTT
He La , LAXHEX
Jacopo De Barbari , DBRJCP
Jacopo De' Barbari , BRBJPD
Jo Zayner , ZYNJOX
Lea Rossi Del Bo , BOXLSS
L'Orfeo Di Monteverdi , DMNLRF
Luigi Mc Mario , MCMLGU
Mario De Rossi , DRSMRA
Menu a'-la-carte , LCRMNE
Mona Lisa , LSIMNO
Niccolo dell'Arca , DLLNCL
Nicola Sap , SPANCL
Oi Xy , XYXOIX
Pellegrino Artusi , RTSPLG
Pinco Pallino , PLLPNC
Salvo Montalbano , MNTSLV
Stack Exchange , XCHSCK
Sonia O'Neill , NLLSNO
Tylynn Ng , NGXTLY
Uy Li , LIXYUX
Xenia Silberberg , SLBXNE
Reference implementation (ATO)
Score
This is code-golf, shortest code wins.