LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Project Euler Problems Help (Urgent)

Hi friends, I need help doing the problems below in LabVIEW. I need a code that is quick and efficient because my code is simply consuming too much time.Smiley Indifferent I want the code without using any inbuilt LabVIEW VIs such as the prime factor.vi.Smiley Happy

 

 

1) Find the greatest product of 6 consecutive digits in the first 1000 decimal digits of Euler's number e.

 

2) By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10001st prime number?

 

3) The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million.

 

4)  2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

 

Thanks

0 Kudos
Message 1 of 35
(3,732 Views)

These are always pretty cool homework problems.

 

What have you tried so far?

Post your code and you'll get comments about how to improve it.

 

0 Kudos
Message 2 of 35
(3,690 Views)

Yeah, let us know what you've tried.

 

I've done these problems myself when I first stated with LabVIEW so I can point you in the right direction

 

-Jim B.

-Jim B
Applications Engineer, National Instruments
CLD, CTD
0 Kudos
Message 3 of 35
(3,684 Views)

Hi-

 

No point reinventing the wheel- please post the working code you mentioned and we can point out how to make it more efficient.

0 Kudos
Message 4 of 35
(3,660 Views)

Ok I am posting the code I did for questions 2,3 & 4. I don't know how to solve question 1. I did'nt implement any formulas in the code since I don't know, which is why the code is taking too much time. Also I haven't put wait ms function since my code was already too slow. I am posting these solutions to convince you guys that I have tried it and it is not the best solution, which is why I am asking for help. Also please don't comment on style guidelines because that is not the intend of posting these solution of mine.

 

I was able to solve a few other questions in Project Euler, but for these 4 questions I am unable to proceed. Smiley Indifferent

 

 

Thanks

 

0 Kudos
Message 5 of 35
(3,650 Views)

Hi,

 

So I looked at your problem 2 (Euler Problem 7) and 3 (Euler Problem 10) and number 2 seems to work fine.  It runs in 8 seconds on my computer which shouldn't be a problem.

 

Problem 3 does take some time because you are currently iterating over every number from 0 to 2,000,000, and checking if it's prime by dividing it by every number less than it.

 

Some improvements:

-One thing to remember with primes is when checking if a number n is prime, you only have to check from 2 up to SQRT(n).  This makes sense when you think about it because if a number is not divisible by any number below its square root, it won't be divible by any number greater than it either.

 

-The way I did this problem is I built an array of primes and checked the next numbers by iterating through the array of primes.  This works because every number can be broken down into prime factors so if a number is not divisible by any primes less than it, it is prime itself.

-Jim B
Applications Engineer, National Instruments
CLD, CTD
0 Kudos
Message 6 of 35
(3,637 Views)

And for your problem 4, you just need to take the prime factorization of all numbers less than 20, combine them where possible, and multiply them together.

 

For instance, if we want the least common multiple of 6, 8, and 10 we would break them down:

 

6 = 2^1 * 3^1
8 = 2^3
10 = 2^1 * 3^0 * 5^1

Then we combine and get:

2^3 * 3^1 * 5^1 = 120.

So 120 is the smallest number divisible by 6, 8, and 10.

 

 

I can't find my LabVIEW code that does it, but that's how you do it.

-Jim B
Applications Engineer, National Instruments
CLD, CTD
0 Kudos
Message 7 of 35
(3,621 Views)

Thanks James-B for your valuable time. Smiley Very Happy I will try questions  3 & 4 again keeping your suggestions in mind. Do you know how to solve question 1? I am absolutely clueless. Smiley Sad

0 Kudos
Message 8 of 35
(3,614 Views)

@Mithun_770 wrote:

Do you know how to solve question 1? I am absolutely clueless. Smiley Sad


First you need to find the first 1000 decimal places of e.  I would recommend putting them into a string and then make a program to put the digits from the string into an array.  Now you just have to go through each subset of 6 digits and multiply them.  If the product is greater than the previous greatest product, store it.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 35
(3,603 Views)

Does anyone know how to solve question 1 ? Just need the idea on how to implement it. I thought I could use the euler constant in LabVIEW but it doesn't have 1000 decimal digits. What can I do to solve it?

0 Kudos
Message 10 of 35
(3,598 Views)