March 5, 2010 3

Michał Kwiatkowski – Sum of Even Fibonacci Numbers

By Corey Haines in Katas, Software Craftsmanship

After a short break, we are back with an interesting kata in Clojure. Michał Kwiatkowski has tackled a project euler problem, finding the sum of the even Fibonacci numbers less than 4 million. Fun, indeed. Included in this katacast are 3 different solutions.

Michał Kwiatkowski is a software developer from Gdańsk, Poland. He builds RoR applications and in his spare time works on open source projects like Pythoscope (http://pythoscope.org). His interests include programming languages, artificial intelligence and automated testing.

Here’s what he says about this katacast:

I started doing kata after watching Micah Martin’s lecture, about 3 weeks ago. I wanted to start simple, so I’ve chosen a very basic problem from Project Euler: finding a sum of even Fibonacci numbers lower than 4 million. Each day, I tried a new technique or programming language. I studied solutions of others. Finally, I’ve settled on a set of three solutions, which are recorded in this video.

Main theme of this kata is different techniques for iteration which may be used in Clojure. First is a functional-style iteration using built-in “loop,” a second is a solution in a little DSL of sorts, via the “iter” library and third solution is based on lazy streams, inspired by Haskell.

Interesting thing about this kata was that even after solving the problem multiple times I could still make stupid mistakes from time to time, and writing a solution would take me 20 minutes instead of a minute. This shows how it’s important to practice basics of our craft *every single day*. There’s also a great value in approaching a problem from different perspectives. I’ve learned a great deal about the problem itself as well as about the tools I used to solve it. It’s a great way to asses strong and weak points of programming languages.

Even though it includes 3 solutions, this katacast is nice and short. I enjoyed watching it a lot.

If you’d like to contact Michał, you can below:

Homepage: http://joker.linuxstuff.pl
Tumblr blog: http://time-loop.tumblr.com
Twitter: infrared
Enjoy:

3 Responses to “Michał Kwiatkowski – Sum of Even Fibonacci Numbers”

  1. britto says:

    It’s always great to see how the “divinity of recursion vs. humanity of iteration” story is told here and there.

    by the way, just a little funny typo: asses -> assess ;)

  2. I enjoyed the last solution which IMHO seemed the most functional one (but I’m still on the way to become a FP pro).

  3. @britto:
    In fact it’s all recursion, even when it doesn’t look like it. Still, syntactic sugar of iter is sweet indeed. :)

    @Jacek:
    The last solution was derived from a Haskell one (see here: http://time-loop.tumblr.com/post/23119160/solution-to-project-eulers-problem-2 ). Indeed streams are very functional, yet IMHO, a more complicated concept than a straight iteration. They read backwards, but because of it they’re highly composable.

    The solution itself can be made even shorter, as suggested by scottjad83 on YouTube, by using (lazy-cat [0 1] …) instead of (cons 0 (cons 1 (lazy-seq …))).

Leave a Reply