Friday, January 30, 2015

Kata: Happy Numbers in Clojure

I've just dome the Happy Numbers kata in Clojure.

It's a simple kata that can be a lot of fun.

I used a mix of TDD and REPL-driven development to code it.

These are the resulting tests in Midje:

and this is the code:

To document the process I commited the code after every passing test and every refactoring. I also commited the REPL history.

You can find the commits step by step here and the code in this repository in GitHub.

I used memoize to avoid repeated computations.

In the next days I will try other suggested optimizations based on the properties of happy numbers.

No comments:

Post a Comment