Created
December 4, 2013 15:46
-
-
Save anonymous/7789813 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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