Tuesday, May 14, 2013

project euler problem 171

Finding numbers for which the sum of the squares of the digits is a square

My old code runs quite slow, needs 9 seconds to get the answer. 

I changed my algorithm a little bit. My approach considered the combinations of those numbers and used recursion. It only takes 0.24 second to get the answer.   

But it is still not good enough. I did not think thoroughly about this problem since my code runs quite fast. When I checked the discussion thread, I found that my approach is not as good as those guys who are using dynamic programming. I rewrote the code, it only needs 4ms to get the answer. 

No comments:

Post a Comment