05-10-2014 11:26 AM
Oh dear, 2147483647 was an overflow error. I am posting the code I did so far on question 1. Please tell me how to get rid of the overflow error. How can I multiply such a huge number ? Multiplication of decimal strings are not allowed and converting to any other Numeric datatype yields the overflow error. How to proceed?
Thanks to all who helped me reach this far.
05-10-2014 11:27 AM
My Question 1 code
05-10-2014 11:52 AM - edited 05-10-2014 12:02 PM
Question 1 asks for the largest product of 6 consecutive digits, so the highest possible value is 9^6 (about 0.5M). There should be no overflow. You should have the 1000 digits as an integer array, and getting the largest product of six consecutive digits is then trivial.
The main problem is probably to get the 1000 digits. A quick internet search shows algorithms that alow for efficient calculation of a near infinite amount of digits, so I would suggest to implement one of those. (for example in 2010 somebody calculated 1,000,000,000,000 digits of e in 224 hours).
For example, a simple algorithm from 1968 can be found here and should be easy to implement in LabVIEW. Try it!.
(Back in 2006 we had a coding challenge to calculate all 35660 digits of 10000! (factorial). The best solutions did it in well under 100ms.)
05-10-2014 12:29 PM
I have already got 1000 digits. The formula I used is mentioned in the block diagram of the code I posted earlier. The problem now is how to convert the string data type to a numerical data type so that multiplication can be employed without any number getting rounded off during conversion due to memory limitation of each data type. Right now the values are stored as strings.
05-10-2014 12:40 PM - edited 05-10-2014 12:41 PM
Well, that's trivial. 😄
Of you have a very long string of decimal digits, just convert it to a I32 array (e.g. use string to byte array, subtract 48, then convert to I32).
05-10-2014 12:54 PM - edited 05-10-2014 01:03 PM
@Mithun_770 wrote:
I have already got 1000 digits.
You got factorials up to 1000 digits and later look at 6 digits each. I don't see where e comes in. Can you explain.
(A nice program to find digits of e is in section 9 here.)
05-10-2014 01:12 PM - edited 05-10-2014 01:15 PM
Hi altenbach, you are right I only took 1000 factorials and I forgot something. I was trying to use this formula which was posted here earlier.
e=SUM( 1^n / n! )
which will yield the series
1 + 1 + 1/2 + 1/6 + 1/24 + ...
So I have only calculated factorials upto 1000 digits. I forgot to do 1/n! and also their entire sum. I will do it now and use the string to byte array you mentioned.
05-12-2014 02:57 AM - edited 05-12-2014 09:18 AM
So did you solve problem 1?
I think the solution is 236196 and I wrote a little LabVIEW program that generates all 1000 digits from scratch and finds the largest product, all in a few milliseconds on my old laptop. See if you get the same solution.
05-12-2014 03:03 AM - edited 05-12-2014 03:03 AM
05-12-2014 04:11 AM
Hi altenbach ,thanks for sharing the answer. No I did'nt get the answer. I convinced everyone here that I took the effort to do it by myself. I even posted my code so far. I was able to do the other 3 questions and even improve it based on suggestions community users gave me here. But question 1 was way too difficult for me even to start with. Every time I needed to progress solving question 1, I must ask here what to do next. And still I did'nt get the answer. I already started feeling bad and so I have given up.
Everybody has got some limitations. By now I have proved that I can't do question 1. A working solution to question 1 is my only help now. By now all of you here know how tough this question is. What that can make a difference now is anyone willing to post the whole solution to this question.
Anyways I would like to thank James-B , crossrulz, ToeCutter,johnsold & altenbach for their helpful suggestions.