Sieve of Eratosthenes

by Marín

Since I had a bad experience with the Sieve of Eratosthenes during a college test I sort of became traumatized with it and tried to avoid it. During this holiday break I decided to tackle on it and I successfully implemented it ruby (not very idiomatic but ruby still)

My favorite parts of this algorithm were:

  • The fact that I don’t have to iterate the whole sieve! I can do it just for sqrt(n) since the factors of any number are always composed by two numbers and one of them is always lower than the sqrt of any given number n.
  • The usage of ruby’s inline if statements

Now I can happily say, my trauma over this is over 🙂