January 31, 2012

Exercise: Sieve of Eratosthenes

After reading an interesting blog post from Robert Martin I started writing this nice algorithm in Ruby (I'm still learning it).

As I'm a refactoring freak, here's the first version:

Nasty right? Then the cleaned up release: