LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Project Euler Problems Help (Urgent)

Oh dear, 2147483647 was an overflow error. Smiley LOL 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.

0 Kudos
Message 21 of 35
(1,375 Views)

My Question 1 code

0 Kudos
Message 22 of 35
(1,374 Views)

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.)

Message 23 of 35
(1,367 Views)

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.

0 Kudos
Message 24 of 35
(1,349 Views)

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).

 

 

0 Kudos
Message 25 of 35
(1,344 Views)

@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.)

0 Kudos
Message 26 of 35
(1,341 Views)

Hi 

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.

0 Kudos
Message 27 of 35
(1,347 Views)

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.

0 Kudos
Message 28 of 35
(1,316 Views)

deleted

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 29 of 35
(1,313 Views)

Hi 

0 Kudos
Message 30 of 35
(1,266 Views)