Musings of a Fondue

Sieve of Sundaram

Original Date: April 7, 2014

I was working through question 10 on Project Euler which requires you to find the sum of all primes below two million. I had written some code to find primes in previous questions, but it was far too slow to accomplish this. I hit Google to find efficient algorithms for prime number generation and came across the Sieve of Eratosthenes and the Sieve of Sundaram.

The article on the Sieve of Eratosthenes had a great gif by Sebastian Koppehel which showed visually how the sieve works. It was very clear and quickly gave you the gist of what was happening.

I thought it would be nice to have something similar for the Sieve of Sundaram so after I worked out how Sundaram’s sieve ticks, I made a similar gif for it.

I used JavaScript, HTML, and CSS to make it. See it in action here

If you want to see the code, right click and select view-source. It was cool to contribute something to a site I rely on so much!