Monday, May 6, 2013

project euler problem 155

Counting Capacitor Circuits

My old code runs quite slow. I checked my code, I found that my code spent too much time on gcd. I optimized the code a little bit to reduce the cost and reduce the time from 18 second to 6 seconds. 

I read the discussion thread and removed "set" in my code. It works faster. Only 1.1 second needed to get the answer. If I changed the number of capacitor to 20, It takes 8.5 second to get the answer. 

Although I learned a little bit coding skill from the problem. This problem is somewhat flawed. The problem only considered simple connection in series or in parallel. It is possible to connect capacitors in Y or delta shape. Then the problem is very difficult to solve.

No comments:

Post a Comment