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,

1. 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.

1. Additionally, an initial vowel or sequence of two vowels represents a 0. aikaCi would be: ai,ka,Ci = (0,1,7)

2. Extra vowels anywhere else in the middle of the text have no value: kauCia is the same as kaCi, 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!

• Can aiaKaci be input? (3 leading vowels) – Erik the Outgolfer Jun 8 '18 at 17:53
• There is also no test case which ends in a consonant; can we assume the input will always end in a vowel? – Erik the Outgolfer Jun 8 '18 at 19:21
• No for 3 leading vowels. In fact, I don't think it makes sense for 3 consequent vowels to occur anywhere in the input (2 English vowels are sometimes needed to represent one Sanskrit vowel sound, but never 3). Can I add that in as an input constraint now or is it too late? – sundar - Reinstate Monica Jun 8 '18 at 19:25
• It's not too late to clarify that the input won't have 3 leading vowels. That won't break any submissions, and I doubt anyone have written longer code to take that into account, and if they have they can simply remove it. Nice first question by the way! :) – Stewie Griffin Jun 8 '18 at 19:41
• In case it helps in some languages: ord(c)%47%10 gives a unique index in [0..9] for each consonant. (With ord("ṅ")=7749 and ord("ñ")=241.) – Arnauld Jun 8 '18 at 20:29

# JavaScript (ES6), 83 bytes

s=>s.replace(s=/(^|[ṅcCjJñkKgG])[aeiou]/g,(_,c)=>o=(s+s).search(c)%10+o,o='')&&o


Try it online!

### How?

We use the following regular expression to match either the beginning of the string or one of the Kaadi consonants, followed by a vowel:

/(^|[ṅcCjJñkKgG])[aeiou]/g


For each match in the input string, we invoke the following callback function that takes the content c of the capturing group as parameter:

(_, c) => o = (s + s).search(c) % 10 + o


We find the value of the consonant by looking for its position in the regular expression (coerced to a string by adding it to itself).

The consonants are ordered in such a way that their value is equal to their position modulo 10:

string   : /  (  ^  |  [  ṅ  c  C  j  J  ñ  k  K  g  G  ]  )  [  a  e  i  o  u  ]  /  g
position : 0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 ...
modulo 10: -  -  -  -  -  5  6  7  8  9  0  1  2  3  4  -  ...


When we match the beginning of the string instead of a consonant, c is an empty string whose position in the regular expression is 0 -- which, conveniently, is the expected result in that case.

Finally, we insert this digit at the beginning of the output string o.

# Retina, 41 bytes

TñkKgGṅcCjJd.[aeiou]
^[aeiou]
0
\D

V


Try it online! Link includes test cases. Explantion:

TñkKgGṅcCjJd.[aeiou]


Translate the consonants that are followed by vowels.

^[aeiou]
0


\D


Delete everything else.

V


Reverse the result.

# Python 2, 93 bytes

lambda s,h=u'ñkKgGṅcCjJ'.find:''.join(h(c)*(0>h(v)<h(c))for c,v in zip(u'ñ'+s,s))[::-1]


An unnamed function accepting a Unicode string which returns a string representation of the base ten result.

Try it online!

# Java 8, 136 126 bytes

s->{for(int i=s.length,t;i-->0;)if("aeiou".contains(s[i]))System.out.print(i<1?0:(t="ñkKgGṅcCjJ".indexOf(s[i-1]))<0?"":t);}


Try it online.

Explanation:

s->{                           // Method with String-array parameter and String return-type
for(int i=s.length,t;i-->0;) //  Loop backwards over the input-characters
if("aeiou".contains(s[i])) //   If the current character is a vowel:
System.out.print(        //    Print:
i<1?                  //     If we're at the first character:
0                    //      Print a 0
:                     //     Else:
(t="ñkKgGṅcCjJ".indexOf(s[i-1]))<0?
//      If the character before the vowel is also a vowel:
""                  //       Print nothing
:                    //      Else:
t);}                //       Print the correct digit of the consonant


# Jelly, 27 bytes

Żµe€Øẹœpṫ€0F“kKgGṅcCjJ”iⱮUḌ


Try it online!

Jelly has built-in for... 1-byte ṅ.

Explanation


Żµ             Prepend 0 to the string.
e€  œp       Split at...
Øẹ           the vowels. (0 is not a vowel)

ṫ€0            For each sublist l takes l[-1:].
If the initial list is empty the result is empty,
otherwise the result is a list contain the last element.
F           Flatten. (concatenate the results)

“kKgGṅcCjJ”iⱮ  Find the index of each character in the list.
Get 0 if not found (i.e., for 0 or ñ)
UḌ             Upend (reverse) and then convert from decimal.

• I didn't find a way to save bytes with that, but O%47%10 gives a unique index in [0...9] for each consonant. (Which means that O%47 with the implicit modulo of ị would allow to pick up the correct value in an array of 10 entries.) – Arnauld Jun 8 '18 at 20:22
• @Arnauld 6;µe€Øẹœpṫ€0O%47ị“ ʠḷ’Œ?’¤Ṛ but also 27 unless it can be golfed. – Jonathan Allan Jun 9 '18 at 1:13

# Python 2, 101 bytes

lambda s,S=u'ñkKgGṅcCjJ':''.join(S.find(c)for c,n in zip(u'ñ'+s,s)if c in(n in'aeiou')*S)[::-1]


Try it online!

# Python 3, 104 102 bytes

lambda s,S='ñkKgGṅcCjJ':''.join(str(S.find(c))for c,n in zip('ñ'+s,s)if c in(n in'aeiou')*S)[::-1]


Try it online!

Saved

• -3 bytes, thanks to Rod
• Well, you can if you add the header, but I forgot the unicode prefix in the strings, after all, it would save a single byte – Rod Jun 8 '18 at 14:47
• @Rod, ah thanks, I'd forgotten about the unicode prefix :) – TFeld Jun 10 '18 at 10:22

# JavaScript (Node.js), 126 bytes

_=>(l=_.match(/[kgñṅcj][aeiou]/gi))?l.map(a=>"ñkKgGṅcCjJ".indexOf(a[0])).reverse.join+(/[ aiueo]/.test(_[0])?0:''):0


Try it online!

• you can save a few bytes by changing x=[..."ñkKgGṅcCjJ"] to just x="ñkKgGṅcCjJ" since indexOf works with Strings too – WaffleCohn Jun 8 '18 at 14:32
• This doesn't seem to treat initial vowels as 0, so fails the test cases 3 and 6 (as can be seen in the Output on TIO). – sundar - Reinstate Monica Jun 8 '18 at 14:45
• @sundar My bad, Fixed. – Luis felipe De jesus Munoz Jun 8 '18 at 14:58

# Red, 152 143 bytes

func[s][t:"ñkKgGṅcCjJ"c: charset t
d: copy{}parse s[opt[1 2 not c(alter d 0)]any[copy n c not c(insert
d(index? find/case t n)- 1)| skip]]d]


Try it online!

f: func[s] [
t: "ñkKgGṅcCjJ"
c: charset t
d: copy {}
parse s [
opt [ 1 2 not c (alter d 0) ]
any [
copy n c not c (insert d (index? find/case t n) - 1)
| skip
]
]
d
]


# MATL, 4847 45 bytes

'ng'98Ztt'y'whw11Y2m)'ykKgGbcCjJ'tfqXEt10<)oP


Try it online!

('b' instead of 'd' to save a byte)
(-2 bytes thanks to Luis Mendo)

MATLAB (and hence MATL) treating strings as a dumb series of bytes made porting @TFeld's Python solution harder than I imagined (maybe a straight loop solution would have been easier here?). Ended up using the alternate 'ng', 'ny' input method, and replacing ng with b at the beginning for easier processing.

Explanation:

        % Implicit input (assume 'junyiKonge')
'ng'   % string literal
98     % 'b'
Zt     % replace substring with another (stack: 'junyiKobe')
t      % duplicate that (stack: 'junyiKobe' 'junyiKobe')
'y'    % string literal
w      % swap elements in stack so 'y' goes before input (stack: 'junyiKobe' 'y' 'junyiKobe')
h      % horizontal concatenation (prepend 'y' to input string) (stack: 'junyiKobe' 'yjunyiKobe')
w      % swap stack (stack: 'yjunyiKobe' 'junyiKobe')
11Y2   % place 'aeiou' in stack (stack: 'yjunyiKobe' 'junyiKobe' 'aeiou')
m      % set places with a vowel to True i.e. 1 (stack: 'yjunyiKobe' 0 1 0 1 0 1 0 0 1)
)      % index into those places (stack: 'jyKd')
'ykKgGdcCjJ' % string literal
tfq    % generate numbers 0 to 9 (stack: 'jyKd' 'ykKgGdcCjJ' 0 1 2 3 4 5 6 7 8 9)
XE     % replace elements in first array which are found in second,
%  with corresponding elements from third
t10<)  % keep only elements that are less than 10 (removes extraneous vowels)
o      % convert from string to double (numeric) array (stack: 8 0 2 5)
P      % flip the order of elements (stack: 5 2 0 8)
% (implicit) convert to string and display

• Thanks, done. Do you know if MATLAB/Octave has anything to index into/iterate through a string across Unicode codepoints instead of bytes? Doesn't look like it, their Unicode support seems atrociously bad in general, but maybe I missed something. – sundar - Reinstate Monica Jul 6 '18 at 7:32
• Also, the MATL manual mentions " if input is a string or character array" in a couple of places - are those two different things? Anything to do with the fancy new double-quoted strings in MATLAB? – sundar - Reinstate Monica Jul 6 '18 at 7:34
• Matlab has unicode2native, but I think that's now what you want. I agree, Unicode support in MATLAB is not the best. And don't get me started with Octave :-D As for MATL, it was designed before the new string data type existed in MATLAB (and I don't like it much anyway), so in MATL a "string" is the same as it used to be in old MATLAB versions: a row vector of chars. I've made a note to clarify that in the documentation, thanks for noticing! – Luis Mendo Jul 6 '18 at 9:05

# Stax, 27 bytes

âΔxñW⌡╪c§âaQ&δ▓äHê╠\$╞╣;→◄vΓ


Run and debug it