Friday, May 23, 2014

project euler problem 413

One child number

This problem is an interesting dynamic programming problem. It does not take me too long to figure out  how to solve the problem. 

I first used a lazy vector to handle the key component of the problem. It soon works after I fixed a couple of bugs. The issue was that my code ran too slow. I then found a better format to reorganize the data, the hashmap! The hashmap use less memory and better performance. But I did not write out a very detailed plan. It proved that this was a unwise decision. I made several stupid mistake and sometime contradictory implementation.  It takes me several hours debugging the code and actually making a plan during debugging. I should write out the plan before coding even if it is a rewrite. Finally I got it write again, the code runs for 6 seconds.

Thursday, May 22, 2014

project euler problem 469

Empty Chairs

This is an interesting problem. But it is simple if one find the shortcut. I would not tell anything about the shortcut. It is fast to solve but you lose a lot to learn if you are only interested in the solution to be submitted. 

I investigated the problem a little bit and then find a recurrent equation. It is routine to find the differential equation that needs to be solved. I asked "Mr. wolframalpha" to solve the equation for me, then the problem becomes easy and clear. When I got the final solution, I was surprised that the result is related to one of Euler's well known contribution to math. I hope everyone can enjoy the problem.