Sunday, April 21, 2013

project euler problem 127

abc-hits

This is an interesting and quite difficult problem in the early problems. I checked my old code. It runs for a long time. I killed it since it seems I still need to wait for a long time after 4 minutes run. I rewrote the code,  after I learned something useful from problem 124. Well, it still takes 3 minutes to finish. 

I checked my code carefully, and reordered some of the code. Then the time needed reduced to 3 second!  I just realize that the order of the code is so important. 

Finally, hk challenged everyone to try the c < 4000001. I rerun my code,  got stuck again! My code need 2 to 3 minutes while hk's solution only needs 12 second.  I read the discussion again. This time, I fully enjoyed the problem and reduced my code's run time to 12 second or so.

I learned a lot of things in this problem. I highly recommend everyone to try this problem on his or her own.

No comments:

Post a Comment