VaultNetwork.net Vault Network Boards
Author Topic: how hard would this be to program? [Locked]
sorrento
Posts: 19
Registered: 2004-1-28 14:09:43
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?
__Bonk__  5 stars
Posts: 5,122
Registered: 2009-7-25 03:04:52
Pie is actually hard to make

 

-----signature-----
I keep my eyes fixed on the sun!
A change in feeling is a change in destiny.
Koneg  3 stars
Title: Evil Genius
Posts: 894
Registered: 2001-12-4 15:31:28
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
Eradiani  3 stars
Title: Moderator/ EvEVault Staff
AE mid to deep

Posts: 527
Registered: 2002-5-3 02:18:49
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-----
Koneg  3 stars
Title: Evil Genius
Posts: 894
Registered: 2001-12-4 15:31:28
Eeeew.


And yea, as I suspected, already written


Quote:

#!/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
Eradiani  3 stars
Title: Moderator/ EvEVault Staff
AE mid to deep

Posts: 527
Registered: 2002-5-3 02:18:49
Koneg posted:

Eeeew.

And yea, as I suspected, already written


Quote:

#!/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-----
Koneg  3 stars
Title: Evil Genius
Posts: 894
Registered: 2001-12-4 15:31:28
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
eodoll  4 stars
Posts: 1,028
Registered: 2002-2-14 12:35:42
What language? I could write it in C in about 5 minutes.
ZartanAround  3 stars
Title: Torpid Curmudgeon
Posts: 768
Registered: 2004-2-6 20:54:09
fortran!

 

-----signature-----
what are nice chickens like you doing in a coop like this?
__Bonk__  5 stars
Posts: 5,122
Registered: 2009-7-25 03:04:52
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.

VaultNetwork.net is an independently operated community forum and is not affiliated with, endorsed by, or technically based on IGN, GameSpy, FilePlanet, GameStats, or the former IGN/GameSpy Vault Network.
References to VaultNetwork.net mean this site/domain. VNBoards-style presentation is a visual homage only. By using this site, you agree to the forum rules.