VERRRRY big numbers

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
dhokarena56
Posts: 179
Joined: Fri Mar 27, 2009 11:52 pm UTC

VERRRRY big numbers

Postby dhokarena56 » Mon Nov 22, 2010 7:25 pm UTC

I am on a quest to destroy my school's servers by using them in a completely pointless quest to find Lychrel numbers. I tried writing a Java program (Java's all I know), but when I inputted 196, the long class just couldn't handle the eventual big numbers.

What language should I pick up to work with pointlessly big numbers (we're talking at least one million digits)?
Come join Dadapedia- the open-source Dadaist novel that anyone can edit.

User avatar
cba
Posts: 72
Joined: Wed Oct 06, 2010 2:58 am UTC
Location: not here...
Contact:

Re: VERRRRY big numbers

Postby cba » Mon Nov 22, 2010 7:29 pm UTC

python seems pretty good at handling big numbers... I cant remember though if I converted the numbers to strings first though and worked with them like that, converting them back to numbers when need be...
For the first time ever! flatland in a mind-boggling 3D!
import antigravity
Image

rflrob
Posts: 235
Joined: Wed Oct 31, 2007 6:45 pm UTC
Location: Berkeley, CA, USA, Terra, Sol
Contact:

Re: VERRRRY big numbers

Postby rflrob » Mon Nov 22, 2010 7:48 pm UTC

cba wrote:python seems pretty good at handling big numbers... I cant remember though if I converted the numbers to strings first though and worked with them like that, converting them back to numbers when need be...


I concur. Python has the Long Integer type which can support integers of arbitrary length:

Code: Select all

foo = 10**1000000 + 42
bar = 53L
print foo % 100
print type(foo)
print type(bar)
Ten is approximately infinity (It's very large)
Ten is approximately zero (It's very small)

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: VERRRRY big numbers

Postby Xeio » Mon Nov 22, 2010 8:43 pm UTC

http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic

Useful wikipedia link, also has resource links for languages with libraries (if it's not in standard library). For java you'd want the java.math.BigInteger class.

the.coding.eye
Posts: 52
Joined: Thu Apr 16, 2009 4:56 am UTC
Contact:

Re: VERRRRY big numbers

Postby the.coding.eye » Mon Nov 22, 2010 9:30 pm UTC

I'm pretty sure the BigInteger class in Java should support numbers that big.
"In theory, theory and practice are the same. In practice, they are not."

archeleus
Posts: 240
Joined: Wed Sep 29, 2010 1:49 pm UTC
Location: Valenvaryon
Contact:

Re: VERRRRY big numbers

Postby archeleus » Tue Nov 23, 2010 6:34 am UTC

Well I do know Java but I prefer using C or C++ to do stuff like this. I can link you to the GNU Bignum library which is only limited by the amount of memory you have.
I write a blog rant here.

User avatar
hotaru
Posts: 1045
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: VERRRRY big numbers

Postby hotaru » Tue Nov 23, 2010 2:25 pm UTC

archeleus wrote:GNU Bignum library which is only limited by the amount of memory you have.

that's actually not true. it's limited by the size of your size_t type, which may actually be smaller than the amount of memory you have. not having size_t large enough to represent the amount of memory you have is arguably a bad idea (gmp is not the only library that assumes that you don't have more than SIZE_MAX bytes of memory), but it is allowed by all the relevant standards, and systems actually do exist that do that.

Code: Select all

factorial product enumFromTo 1
isPrime n 
factorial (1) `mod== 1

User avatar
Jplus
Posts: 1721
Joined: Wed Apr 21, 2010 12:29 pm UTC
Location: Netherlands

Re: VERRRRY big numbers

Postby Jplus » Tue Nov 23, 2010 4:13 pm UTC

What hotaru said is true, but note that you can fit about 2.25 decimal digits in a byte. If your computer has 1 GB of working memory (which will usually be less than SIZE_MAX), then you can in theory already store about 2.4 billion digits.

If you're going to use a lot of memory I wouldn't recommend using Java though. Java is known for its large memory overhead and associated temporary delays. Python will deal much more efficiently with your memory, and C and C++ even more so.
"There are only two hard problems in computer science: cache coherence, naming things, and off-by-one errors." (Phil Karlton and Leon Bambrick)

coding and xkcd combined

(Julian/Julian's)

Moose Hole
Posts: 398
Joined: Fri Jul 09, 2010 1:34 pm UTC

Re: VERRRRY big numbers

Postby Moose Hole » Tue Nov 23, 2010 4:17 pm UTC

dhokarena56 wrote:I am on a quest to destroy my school's servers
Jplus wrote:Java is known for its large memory overhead
Sounds like Java is the right choice then.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 8 guests