sorrento
Posts:
258
Registered:
Jan 28, '04
Extended Info (if available)
Real Post Cnt: 204
User ID: 888,465
|
Subject:
how hard would this be to program?
|
Just curious, I've had some programming classes in the past. Probably not too hard, I don't know, I'm asking: enter any number, say 88,000 response: eighty eight thousand. converts any number to English representation of said number. how high, say up to a sextillion, or higher even. not asking for any particular reason. any programmers that can answer? sounds simple/but it's actually hard? or easy as pie?
-----signature-----
(none)
|
Link to this post
|
__Bonk__
Posts:
53,947
Registered:
Jul 25, '09
Extended Info (if available)
Real Post Cnt: 53,339
User ID: 1,364,654
|
Subject:
how hard would this be to program?
|
Pie is actually hard to make
-----signature-----
I keep my eyes fixed on the sun! A change in feeling is a change in destiny.
|
Link to this post
|
Koneg
Title: Evil Genius
Posts:
31,388
Registered:
Dec 4, '01
Extended Info (if available)
Real Post Cnt: 28,579
User ID: 530,943
|
Subject:
how hard would this be to program?
|
Incredibly trivial to write.. and probably already has been.
-----signature-----
* First rule of a gun fight: Have a gun. | "Any sufficiently advanced idiocy is indistinguishable from trolling." -- Arthur C Clarke
|
Link to this post
|
Eradiani
Title: Moderator/ EvEVault Staff AE mid to deep
Posts:
31,200
Registered:
May 3, '02
Extended Info (if available)
Real Post Cnt: 30,155
User ID: 675,153
|
Subject:
how hard would this be to program?
|
wouldn't be hard at all.. there's some very simple ways of doing it but wouldn't be good programming. The only real thought would be on handling the tens in each number cluster (as like sixty-two needs to add a hyphen where sixty doesn't) So a very basic and simple way would be like know your max number (say 999,999,999,999,999) or 999 trillion you can just do a series of if statements like this: generic c# exmaple You'll first likely want to setup a string table that has (zero[this is important so you don't have to -1 all the time],one,two,three,four,five,six,seven,eight,nine) outstring = ''; If (number >= 100 trillion) { tempnumber = number / 100 trillion; number = number % 100 trillion; outstring += tempstring[tempnumber] + 'hundred'; if (number < 1 trillion) outstring += tempstring[tempnumber] + ' trillion'; } if (number >= 10 trillion) { tempnumber = number / 10 trillion; number = number % 10 trillion; outstring += tempstring[tempnumber] + 'ty'; if (number >= 1 trillion) outstring += '-'; else outstring += ' trillion'; } if (number >= 1 trillion) { tempnumber = number / 1 trillion; number = number % 1 trillion; outstring += tempstring[tempnumber] + ' trillion'; } continue on through billions/mill/etc etc
-----signature-----
|
Link to this post
|
Koneg
Title: Evil Genius
Posts:
31,388
Registered:
Dec 4, '01
Extended Info (if available)
Real Post Cnt: 28,579
User ID: 530,943
|
Subject:
how hard would this be to program?
|
Eeeew.
And yea, as I suspected, already written
#!/usr/bin/perl
use Lingua::EN::Numbers qw(num2en num2en_ordinal);
$input = @ARGV[0] || die "Give me something to convert you n00b";
chomp($input);
$input =~ s/\,//g;
if($input =~ /^[0-9]+$/) {
print num2en($input) . "\n";
} else {
print "Try this with numbers? Maybe?\n";
}
-----signature-----
* First rule of a gun fight: Have a gun. | "Any sufficiently advanced idiocy is indistinguishable from trolling." -- Arthur C Clarke
|
Link to this post
|
Eradiani
Title: Moderator/ EvEVault Staff AE mid to deep
Posts:
31,200
Registered:
May 3, '02
Extended Info (if available)
Real Post Cnt: 30,155
User ID: 675,153
|
Subject:
how hard would this be to program?
|
Koneg posted:
Eeeew. And yea, as I suspected, already written #!/usr/bin/perl use Lingua::EN::Numbers qw(num2en num2en_ordinal); $input = @ARGV[0] || die "Give me something to convert you n00b"; chomp($input); $input =~ s/\,//g; if($input =~ /^[0-9]+$/) { print num2en($input) . "\n"; } else { print "Try this with numbers? Maybe?\n"; }
LOL I'm sure they are looking for someone to make it themselves.. not pass it to a pre-made function
-----signature-----
|
Link to this post
|
Koneg
Title: Evil Genius
Posts:
31,388
Registered:
Dec 4, '01
Extended Info (if available)
Real Post Cnt: 28,579
User ID: 530,943
|
Subject:
how hard would this be to program?
|
Eradiani posted: LOL I'm sure they are looking for someone to make it themselves.. not pass it to a pre-made function
**scratches head**
I would bet real money this function/library exists for every programming language you care to name, but hey... Have fun re-inventing that wheel if it really makes you happy.
-----signature-----
* First rule of a gun fight: Have a gun. | "Any sufficiently advanced idiocy is indistinguishable from trolling." -- Arthur C Clarke
|
Link to this post
|
eodoll
Posts:
17,153
Registered:
Feb 14, '02
Extended Info (if available)
Real Post Cnt: 15,943
User ID: 645,592
|
Subject:
how hard would this be to program?
|
What language? I could write it in C in about 5 minutes.
-----signature-----
(none)
|
Link to this post
|
ZartanAround
Title: Torpid Curmudgeon
Posts:
13,775
Registered:
Feb 6, '04
Extended Info (if available)
Real Post Cnt: 11,365
User ID: 892,117
|
Subject:
how hard would this be to program?
|
fortran!
-----signature-----
what are nice chickens like you doing in a coop like this?
|
Link to this post
|
__Bonk__
Posts:
53,947
Registered:
Jul 25, '09
Extended Info (if available)
Real Post Cnt: 53,339
User ID: 1,364,654
|
Subject:
how hard would this be to program?
|
http://www.youtube.com/watch?v=N9qYF9DZPdw
-----signature-----
I keep my eyes fixed on the sun! A change in feeling is a change in destiny.
|
Link to this post
|
Eradiani
Title: Moderator/ EvEVault Staff AE mid to deep
Posts:
31,200
Registered:
May 3, '02
Extended Info (if available)
Real Post Cnt: 30,155
User ID: 675,153
|
Subject:
how hard would this be to program?
|
Koneg posted:
Eradiani posted: LOL I'm sure they are looking for someone to make it themselves.. not pass it to a pre-made function
**scratches head** I would bet real money this function/library exists for every programming language you care to name, but hey... Have fun re-inventing that wheel if it really makes you happy.
Well the way it was asked made it sound like it was a lab for a programming course in college (or at the very least you had to assume that there wasn't something out there that already did this). so yeah you sort of have to re-invent the wheel for that sort of thing
-----signature-----
|
Link to this post
|
GrymmDAOC
Posts:
8,605
Registered:
Dec 6, '01
Extended Info (if available)
Real Post Cnt: 6,931
User ID: 534,161
|
Subject:
how hard would this be to program?
|
Now write it in Intercal!
-----signature-----
Now speccing 2h sword IRL.
|
Link to this post
|
Aerlinthian
Posts:
66,222
Registered:
May 7, '01
Extended Info (if available)
Real Post Cnt: 65,491
User ID: 94,919
|
Subject:
how hard would this be to program?
|
I thought real programers wrote in assembly.
-----signature-----
(none)
|
Link to this post
|
Scarne
Title: Capo di Scientifico
Posts:
27,710
Registered:
Jul 23, '01
Extended Info (if available)
Real Post Cnt: 22,798
User ID: 272,061
|
Subject:
how hard would this be to program?
|
It's easy since there are some basic patterns. First, groups the digits of the number into the groups of three as we do with commas when writing the number out. Each group of the is written as "{blah-blah-blah} {billion|million|thousand|[nothing]|etc}" with a separator between groups. This lets you write out numbers as big as you have the names of the groups for. For the groups of three digits themselves, they break down into "{blah} hundred {blah-blah}". So the hundreds digit is taken care of. Then you just need to do all the special case logic to write out the tens and ones digit for the group. There are a few other special cases to suss out like skipping groups of "000", but it shouldn't be too bad.
-----signature-----
E Pluribus Unum
|
Link to this post
|
RHWarrior
Posts:
5,026
Registered:
Sep 30, '09
Extended Info (if available)
Real Post Cnt: 5,021
User ID: 1,372,077
|
Subject:
how hard would this be to program?
|
I used to be a Perl programmer, then I took a Python to the knee!
-----signature-----
"Drink coffee - do stupids things faster with more energy! ...and I'm all out of beans..." -me "You guys need to stop dick riding wow and compare everything to it. It never invented a godamn thing, just made it popular. " -tinkly
|
Link to this post
|