tags:

views:

495

answers:

5

I'm solving problems in Project Euler. Most of the problems solved by

  1. big numbers that exceeds ulong,
Ex : ulong number = 81237146123746237846293567465365862854736263874623654728568263582;
  1. very sensitive decimal numbers with significant digits over 30

Ex : decimal dec = 0,3242342543573894756936576474978265726385428569234753964340653;

  1. arrays that must have index values that exceeds biggest int value.

Ex : bool[] items = new bool[213192471235494658346583465340673475263842864836];

I found a library called IntX to solve this big numbers. But I wonder how can I solve this problems with basic .NET types ?

Thanks for the replies !

+7  A: 

Well, for the third item there you really don't want to use an array, since it needs to be allocated that big as well.

Let me rephrase that.

By the time you can afford, and get access to, that much memory, the big-number problem will be solved!

To answer your last question there, there is no way you can solve this using only basic types, unless you do what the makers of IntX did, implement big-number support.

Might I suggest you try a different programming language for the euler-problems? I've had better luck with Python, since it has support for big numbers out of the box and integrated into everything else. Well, except for that array, you really can't do that in any language these days.

Lasse V. Karlsen
definitely try Python; its a good fit
Mitch Wheat
Java has BigInteger and BigDecimal too
Malfist
+4  A: 
Allan Simonsen
+1  A: 

Well, I suggest you take look at this other answer to see how I solved the Big Numbers problem. Basically, you need to represent numbers in another way ...

bruno conde
interesting, I like the solution, thanks.
Canavar
A: 

Another options might be to use the BigInt type that is available in F#: http://cs.hubfs.net/forums/thread/887.aspx

peSHIr
A: 

Most of the problems solved by

  1. big numbers that exceeds ulong,
  2. very sensitive decimal numbers with significant digits over 30
  3. arrays that must have index values that exceeds biggest int value.

Most of the problems are designed to fit within 64 bit longs. There are one or two which require bigger integers, but not many. None I've seen require decimal numbers with more than 30 digits, and none require arrays larger than a few thousand entries.

Remember that the correct solutions to the problems should run in a few seconds at most, and populating an array of 213192471235494658346583465340673475263842864836 bits will take 10^30 years.

Pete Kirkham