Algorithms
I think I am learning a valuable lesson today. I was working on problem 3 of the project euler problems. Essentially I have to find the largest prime factors
Here is the situation, I was able to create a program to find the largest Prime-factors.
Now is the time you would think to yourself, “ hey he’s done!”
Normally I would agree with you, however yes and no.
Yes, in that I was able to create tests to check if numbers were prime at all. I was also able to make a list of the primes that can go up to the input number.Not only that, I created a list where I have all of my prime factors.
Maybe you can smell my problem. It works great for relatively small problems.
However I am supposed to find the largest prime of this beast 600851475143.
What?!
My mistake is I iterate through the large number many times. I have 2 range functions and 2 mod functions without caps. I let my computer run for about 10 minutes and I was not able to get an answer.
So lesson of the day. Just because it is a way to find prime factors, doesn’t mean it’s right.
Finding a way to optimize your code is important.
Best,
Merl