Skip to content

Instantly share code, notes, and snippets.

@eddyb
Forked from anonymous/gist:7789813
Last active December 30, 2015 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddyb/7789849 to your computer and use it in GitHub Desktop.
Save eddyb/7789849 to your computer and use it in GitHub Desktop.
// array per definizione nomi da 0 a 19
static a19: [&'static str, ..20] = [
"", "uno", "due", "tre",
"quattro","cinque", "sei", "sette", "otto",
"nove", "dieci", "undici", "dodici",
"tredici", "quattordici", "quindici",
"sedici", "diciassette", "diciotto",
"diciannove"
];
static dec: [&'static str, ..8] = [
"venti", "trenta",
"quaranta", "cinquanta", "sessanta",
"settanta", "ottanta", "novanta"
];
fn num2text(n: uint) -> ~str {
match n {
0..19 => a19[n].to_owned(),
20..99 => {
let mut d = dec[n/10-2];
let t = n % 10;
if t == 1 || t == 8 {
d = d.slice_chars(0, d.char_len() - 1);
}
d + num2text(t) // this is concatenation
}
// other case
_ => ~"pippo"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment