A124015 thoughts

Hans Havermann pxp at rogers.com
Sun Nov 5 02:29:38 CET 2006


Joseph Biberstine:

> 	For anyone interested, this Mathematica function, eng[], will (as  
> usual, barring bugs) give the American English name for integers on  
> 0 to 10^21-1.  Extension of the upper bound should be plain to  
> implement (just one line of code -- observe the trend).

I forget where I found the following bit of elegant code, but it  
essentially does the same thing as yours (except use a hyphen instead  
of a space between the tens and units for tens > 20):


Ones[n_, pad_:0] := If[Mod[pad, 10] > 0, "-", ""] <> {"", "one",  
"two", "three", "four", "five", "six", "seven", "eight", "nine",  
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",  
"sixteen", "seventeen", "eighteen", "nineteen"}[[n + 1]]

Tens[n_] := {"", "twenty", "thirty", "forty", "fifty", "sixty",  
"seventy", "eighty", "ninety"}[[n]]

LastThree[n_] := LastThree[n] = Module[{h = Quotient[n, 100], m = Mod 
[n, 100]}, If[n > 99, Ones[h, 0] <> " hundred ", ""] <> If[m < 20,  
Ones[m], Tens[Quotient[m, 10]] <> Ones[Mod[m, 10], m]]]

Powers[n_] := Powers[n] = {"", " thousand", " million", " billion", "  
trillion", " quadrillion", " quintillion", " sextillion", "  
septillion", " octillion", "nonillion", " decillion", " undecillion",  
" duodecillion", " tredecillion", " quattuordecillion", "  
quindecillion", " sexdecillion", " septendecillion", "  
octodecillion", " novemdecillion", " vigintillion"}[[n]]

(*NumberName[0] := "zero"*)

NumberName[n_Integer] := Module[{db = Reverse[MapIndexed[If[#1 == 0,  
"", LastThree[#1] <> Powers[#2[[1]]] <> " "] &, FromDigits[#, 10] & / 
@ Reverse /@ Partition[Reverse[IntegerDigits[n, 10]], 3, 3, {1, 1},  
{}]]]}, StringDrop[StringJoin @@ db, -1]]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.seqfan.eu/pipermail/seqfan/attachments/20061104/cb8f8d78/attachment-0003.htm>


More information about the SeqFan mailing list