Quite challenging as you cannot brute force a solution, I tried, the solution takes a long time to run. Had a go with TDD for a change, actually made it easy to think the problem through, even though I came up with the wrong answer. My solution would only work when the largest prime is less than the square root of the argument value. Solution
Easiest solution to implement for me was trial division algorithm is implemented on the page in python this is easy to convert to C#. Implemented in the tests this took 1-11ms to run which isn't bad considering the numbers magnitude, 600851475143.
Lists and enumerable range types do have a limit in their sizes which isn't too bad, I was playing around the idea of a linq solution which I think would work for smaller numbers.
Trying to keep a clear head and getting out I went to the zoo.
No comments:
Post a Comment