You have come across an old Indian manuscript, one that describes mounds of buried treasure. The manuscript also tells you the location of the treasure, except that some crucial numbers have been encoded indirectly into the text. You figure out that the text uses a 'Kaadi' system, a restricted subset of the more common 'Katapayadi' system.
(The Katapayadi system is an ancient Indian system to encode numerals as letters, often used as mnemonics to remember long numbers.)
Your task here is to decode text encoded in the Kaadi system and print out the numerical value.
Details
Input characters
The Kaadi system is based on the Katapayadi system's rules, but uses only the first row of consonants. Your text here has been transliterated to Latin alphabet, and is known to contain only:
- vowels 'a','e','i','o','u'
- consonants 'g','k','c','j', and their capital forms (to represent the aspirated form of those consonants), and 'ṅ' and 'ñ'.
(You may choose to receive and handle 'ṅ' as 'ng' and 'ñ' as 'ny' if that's more convenient in your language.)
Value assignment
In this system,
each consonant when followed by a vowel has a digit associated with it. These are:
'k'=>1, 'K'=>2,
'g'=>3, 'G'=>4,
'ṅ'=>5,
'c'=>6, 'C'=>7,
'j'=>8, 'J'=>9,
'ñ'=>0
Note however, that these values apply only when these consonants are followed by a vowel. kacCi
has the same value as kaCi
(ka
,Ci
=(1,7)) since the middle c is unaccompanied by a vowel.
Additionally, an initial vowel or sequence of two vowels represents a 0.
aikaCi
would be:ai
,ka
,Ci
= (0,1,7)Extra vowels anywhere else in the middle of the text have no value:
kauCia
is the same askaCi
, the extra vowels can be ignored.
Final numeric value
Once the digit values of the letters have been figured out, the final numerical value is obtained as the reverse order of those digits i.e. the first digit from the text is the least significant digit in the final value.
Eg.
GucCi
has Gu
and Ci
, so (4, 7), so the final value is 74.
kakakaGo
is (1,1,1,4), so the the answer is 4111.
guṅKo
is (3,2), so encodes 23. (gungKo
if using ASCII-equivalent.)
Input
- A string containing a Kaadi-encoded text
- will contain only vowels and the above consonants
- the vowels are always in lowercase and occur in groups of no more than 2
- you may choose to accept the letters for 5 and 0 either as their Unicode characters 'ṅ' and 'ñ' or as their ASCII equivalents 'ng' and 'ny' (they're in lowercase in either form)
- you may assume there are no spaces or punctuations
Output
- The numerical value of the text, as given by the above rules
- for empty input, an empty output or any false-y output in your language of choice is acceptable, in addition to 0
- for invalid input (input with anything other than vowels and the above consonants), the output is undefined - anything goes
Test cases
"GucCi"
=> 74
"kakakaGo"
=> 4111
"aiKaCiigukoJe"
=> 913720
""
=> 0 //OR empty/falsey output
"a"
=> 0
"ukkiKagijeCaGaacoJiiKka"
=> 1964783210
"kegJugjugKeg"
=> 2891
"guṅKo"
=> 23
"Guñaaka"
=> 104
"juñiKoṅe"
=>5208
(the last ones can be:
"gungKo"
=> 23
"Gunyaaka"
=> 104
"junyiKonge"
=>5208
if you prefer that.)
Standard rules for I/O and loopholes apply. May the best golfer win!
aiaKaci
be input? (3 leading vowels) \$\endgroup\$ord(c)%47%10
gives a unique index in[0..9]
for each consonant. (Withord("ṅ")=7749
andord("ñ")=241
.) \$\endgroup\$