Talk:Number names: Difference between revisions

Content added Content deleted
(locale)
(PARI/GP code doesn't work.)
Line 22: Line 22:
Since the task deals with a natural language, a program's output should follow the normal language usage. How do you pronounce 1,001? "one thousand <i>and</i> one", not "one thousand, one". Currently Java, Ruby, Basic and Python solutions, probably among others, should be considered inadequate. --[[User:Ledrug|Ledrug]] 21:51, 22 June 2011 (UTC)
Since the task deals with a natural language, a program's output should follow the normal language usage. How do you pronounce 1,001? "one thousand <i>and</i> one", not "one thousand, one". Currently Java, Ruby, Basic and Python solutions, probably among others, should be considered inadequate. --[[User:Ledrug|Ledrug]] 21:51, 22 June 2011 (UTC)
: That's probably a matter for local dialect variance. I pronounce it "one thousand, one", myself. Has a nice rhythmic pattern to it when counting aloud. "One ''thou''sand ''one''. One ''thou''sand ''two''. One ''thou''sand ''three''." etc. (I've been very, very bored in the past...) --[[User:Short Circuit|Michael Mol]] 13:12, 23 June 2011 (UTC)
: That's probably a matter for local dialect variance. I pronounce it "one thousand, one", myself. Has a nice rhythmic pattern to it when counting aloud. "One ''thou''sand ''one''. One ''thou''sand ''two''. One ''thou''sand ''three''." etc. (I've been very, very bored in the past...) --[[User:Short Circuit|Michael Mol]] 13:12, 23 June 2011 (UTC)

== PARI/GP Code Doesn't Work ==

The code doesn't seem to work for numbers larger than three digits.

Using PARI/GP via the web on this page: [https://pari.math.u-bordeaux.fr/gp.html https://pari.math.u-bordeaux.fr/gp.html]

<lang parigp>Eng(n:int)={
my(tmp,s="");
if (n >= 1000000,
tmp = n\1000000;
s = Str(Eng(tmp), " million");
n -= tmp * 1000000;
if (!n, return(s));
s = Str(s, " ")
);
if (n >= 1000,
tmp = n\1000;
s = Str(Eng(tmp), " thousand");
n -= tmp * 1000;
if (!n, return(s));
s = Str(s, " ")
);
if (n >= 100,
tmp = n\100;
s = Str(Edigit(tmp), " hundred");
n -= tmp * 100;
if (!n, return(s));
s = Str(s, " ")
);
if (n < 20,
return (Str(s, ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "ninteen"][n]))
);
tmp = n\10;
s = Str(s, [0, "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"][tmp]);
n -= tmp * 10;
if (n, Str(s, "-", Edigit(n)), s)
};
Edigit(n)={
["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"][n]
};

test_nums = [1, 23, 456, 7890, 12345, 678901, 2345678];
for (x = 1, #test_nums, print(test_nums[x] " = " Eng(test_nums[x])));</lang>

This is the output:

<lang parigp>1 = one
23 = twenty-three
456 = four hundred fifty-six
7890 = eight hundred ninety
12345 = three hundred forty-five
678901 = nine hundred one
2345678 = six hundred seventy-eight</lang>

--[[User:Chuck Coker|Chuck Coker]] ([[User talk:Chuck Coker|talk]]) 09:02, 23 June 2019 (UTC)