Saturday, February 16, 2013

Project Euler - Problem 005

So I just finished problem 5 and it was actually quite easy. I was able to just put a while loop around a simple function call to see if all numbers 1 through 20 evenly divided into a number:

 def isEvenlyDivisible(n: Int) = (1 until 20) forall (n % _ == 0)  

Though, my program did take 12 seconds to run so I still think there are some optimizations that could be done to get it to run a little faster.

Actually, I just made a few enhancements and got it to finish in 7 seconds. I'd like to see if this can be done faster but for now, it's time to take on problem 6.

No comments:

Post a Comment