Tuesday, March 14, 2017

5 down, 284 to go

Finding the least common multiple of the first n integers, did two approaches. First was to just increment a target lcm by 2 and check to see if 2 - n all go into the target lcm evenly. That one is only 9 lines and works fast up to n = 10. The second approach was to use a matrix to keep track of all the prime factors I found* for each integer (the value in the matrix is the number of occurrences of that prime factor, while the index is the factor), then compare each prime factor index value in a temporary matrix to see if the new one is larger.

My big revelation in this problem was one that gave me a much more elegant solution to another.

I'm starting over, by the way, when I start learning Swift.  More on that soon, I hope.

No comments:

Post a Comment