Say, that gives me an idea as the point is to try to make calculations like humans rather than like itself. If you didn't understand it, people in grade school are often taught to do something like this:The solution I came up with was to place the numbers into a basic c-array of integers. For example, the number 165 would be represented as x[5,6,1]. 5 goes in the 0th position, 6 in the 1st, and 1 in the 2nd. Any integer can be represented by breaking it down into its n * 10^x, with x being it's position in the array. I then did arithmetic (+, -, *, /) on each element between the two arrays carrying digits to the next element as needed. I am sure there are much more elegant (and memory friendly!) solutions to this problem, but using this methodology I was able to calculate very large integers (e.g. 300!) in a matter of a few seconds.
This solution worked well enough that I made my own Obj-C BigInteger class out of it (and rudimentary iPhone big integer calculator), passing it NSStrings representing the numbers, then converting them to c-arrays to do the calculations, then returning a NSString as the result.
24
X15
---
120
+240
----
360
where you must take each digit one at a time, multiply it, and then take the sum of all of those numbers. A computer, I think, just does it. However, you must instead store them as an index of an array or a linked list as you would overflow the variables type if it was an int and lose accuracy as a double.
However, how you did it confuses me. The question is how did you expand a basic array as more digits were needed? Would it be beneficial to, instead, use a linked list as you never know what the length of the number is or was this intentional to prevent complications?
Last edited: