Skip to content

Instantly share code, notes, and snippets.

Created December 4, 2013 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save anonymous/7789813 to your computer and use it in GitHub Desktop.
Save anonymous/7789813 to your computer and use it in GitHub Desktop.
// array per definizione nomi da 1 a 19
static a19: [&'static str, ..19] = ["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 => ~"",
1..19 => a19[n-1],
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