Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numbers that exceeds basic types in C#

Tags:

c#

.net

types

math

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 !

like image 823
Canavar Avatar asked Dec 08 '22 08:12

Canavar


1 Answers

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.

like image 156
Lasse V. Karlsen Avatar answered Dec 09 '22 22:12

Lasse V. Karlsen