Output the spoken names of numbers used on planet Flapus
Retina, Colopee'pokri, 165 157 143 127 123 bytes
(.+)(.)
$2'$1
0
Kuzla
1
Ponara
2
Boqkel
3
Colopee
4
Vruenat
5
Foham
6
Stikty
7
Kricola
(?<='.*[iou])[a-z]+
T`L`l`'.+
zla'
The trailing linefeed is significant.
Try it online!
Explanation
(.+)(.)
$2'$1
We start by bringing the trailing digit to the front and inserting an apostrophe after it. Note that this leaves single-digit numbers unchanged, since the regex doesn't match - so those never get an apostrophe in the first place.
0
Kuzla
1
Ponara
2
Boqkel
3
Colopee
4
Vruenat
5
Foham
6
Stikty
7
Kricola
This replaces each digit with its full name, regardless of where it appears.
(?<='.*[iou])[a-z]+
This shortens all the digit names that appear after an apostrophe. Note that only the vowels iou
appear first in a digit name, so we check a position that is right after one of those, and after an apostrophe and then match (and remove) all lower case letters that follow that position. Since we've inserted the digit names in title case, this will stop before the next digit.
T`L`l`'.+
This uses transliteration to turn all upper case characters, L
, into their lower case counterpart, l
, provided they are found in a match that starts with '
(in order to leave the leading capital untouched).
zla'
The only thing that's left is correctly handling multiples of (octal) 10. In that case, we'll have a result starting with Kuzla'
, which we want to start with Ku
instead. So we simply remove all occurrences of zla'
.
Java (1.8) - Vruenat'fobo (486 340 bytes)
Just when I thought I couldn't possibly golf this any more, I found another 33 bytes! Very pleased! Biggest savings were from switching to char arrays (shorter to upper/lowercase), and reusing the input string array for the words.
Discovering loads of golfing tricks, down to under 400! In theory I could still reduce this more, as I said a function would be ok in the rules, whereas this is a full program.
Updated Using Martin Büttner's approach, I refactored to use regex instead. Managed to save another 10 bytes! Thanks Martin.
interface F{static void main(String[]n){String t="",o,a=n[0];n="Kuzla,Ponara,Boqkel,Colopee,Vruenat,Foham,Stikty,Kricola".split(",");int i=0,l=a.length()-1;char f=a.charAt(l);o=n[f-48]+(l>0?"'":"");while(i<l)t+=n[a.charAt(i++)-48];o+=t.replaceAll("(?<=.*[iou])[a-z]+","").toLowerCase();if(f==48)o=o.replace("zla'","");System.out.print(o);}}
Ungolfed
interface Flapus {
static void main(String[] names) {
String temp="",out, a = names[0];
names = "Kuzla,Ponara,Boqkel,Colopee,Vruenat,Foham,Stikty,Kricola".split(",");
int i=0, last = a.length()-1;
char lastchar = a.charAt(last);
out=names[lastchar-48]+(last>0?"'":"");
while(i<last) {
temp+=names[a.charAt(i++)-48];
}
out+=temp.replaceAll("(?<=.*[iou])[a-z]+", "").toLowerCase();
if (lastchar==48) {
out=out.replace("zla'","");
}
System.out.print(out);
}
}
JavaScript (ES6), 171
n=>(x='Kuzla Ponara Boqkel Colopee Vruenat Foham Stikty Kricola ku po bo co vru fo sti kri'.split` `,r=x[d=+(n=[...n]).pop()],n.map(d=>r+=x[+d+8],n[0]?r=d?r+"'":'Ku':0),r)
Test
F=n=>(
x='Kuzla Ponara Boqkel Colopee Vruenat Foham Stikty Kricola ku po bo co vru fo sti kri'.split` `,
r=x[d=+(n=[...n]).pop()],
n.map(d=>r+=x[+d+8],n[0]?r=d?r+"'":'Ku':0),
r
)
console.log=x=>O.textContent+=x+'\n'
o=''
for(i=0;i<999;i++)
o+=i.toString(8) +':'+ F(i.toString(8))+(i%8!=7?' ':'\n')
console.log(o)
#O { font-size:12px }
<pre id=O></pre>