Project Euler is getting easier!

For the last 2 days, I have been catching up on PHP OOP via PHP Objects, Patterns, and Practice. I figure a change of pace is good – I need to do some problem-solving!!!

Quickest way to find things to do is Project Euler. I have solved Problem 1 and 2 before in Project Euler in different language. The most memorable one were the time I used Bash scripting (It really isn’t a language for math, I know, but I want to try!).

This time is by far the quickest I have done it. I don’t know if it just because I more used to programming now, or if PHP is just that much easier.

I also found that combing Project Euler with PHP Cookbook was very helpful in learning the PHP built-in functions. I read the problem and started browsing through the Cookbook for possible functions that I can experiment with. I was able to significantly reduce my code length. For example, in my previous coding for one of the Fibonacci sequence problem, I had used multiple enclosing loops to refer back to the last two number and sum them together. This time, I used prev() and end() to point to the last two number of the array and sum them together – in one loop. I also experimented with array_filter to replace one of the foreach loop. I found it to much more concise.

My code is so much shorter and easier to read! Is it strange that I am getting the sort of feeling that one would get after cleaning their room!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.