Friday Puzzler: Sieve of Eratosthenes

This post is more than 2 years old.

It's been a long time since I posted a Friday Puzzler, but as I was perusing Khan's CS courses this morning (which look really cool!) I came across this fascinating discourse on prime numbers: Sieve of Eratosthenes.

Your challenge today is simple - watch the video (via the link above or embed below) - and once the theory is discussed, do not look at the full solution. Write up a solution in ColdFusion and post your answer below. Please remember to use a Gist or Pastebin link.

As a prize today I can offer four gold badges, two Klout perks, and a couple Facebook likes.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by andy matthews posted on 11/2/2012 at 5:18 PM

Lemme guess. I don't actually qualify for the Klout perk though...amirite?

Comment 2 by Jason Dean posted on 11/2/2012 at 5:38 PM

Here is my attempt. Thanks Ray.

https://gist.github.com/400...

Comment 3 by Raymond Camden posted on 11/2/2012 at 5:39 PM

@JD: Slick - haven't seen arraySet used in a *long* time, and that is a perfect example.

Comment 4 by Jason Dean posted on 11/2/2012 at 5:48 PM

I just updated it to make it prettier.

Comment 5 by Tyler Clendenin posted on 11/2/2012 at 7:15 PM

I don't know if you've ever been, but I sugest checking out http://projecteuler.net/

It's great fun (in a CS geeky way), and the Sieve of Eratosthenes is pretty essential to a lot of early problems.

Comment 6 by Tami Burke posted on 11/2/2012 at 7:43 PM

Oh Ray, I worked this up in CF10 testing as a memory load test w/ Dan Wilson.... Lemme see if I can dig it up.

Comment 7 by Raymond Camden posted on 11/2/2012 at 7:48 PM

@Tami: Oh that's sweet!

@Tyler: Will check it out. This concept fascinated me. I especially love how it is over 2000 years old.

Comment 8 by Duncan Nisbett posted on 11/2/2012 at 7:54 PM

Ray, delete my first comment if you would. Didn't realize comments would auto format the way it did. Here is my interpretation of finding primes, http://pastebin.com/kGKseytC.

Comment 9 by Raymond Camden posted on 11/2/2012 at 7:55 PM

@Duncan: Deleted. Going to start running these demos soon.

Comment 10 by Tami Burke posted on 11/2/2012 at 8:09 PM

http://pastebin.com/embed_j... (ugh on the ugly Pastebin escaping)

We did this up to 35,000,000 in order to perform memory testing of CF10. Running multiples copies of the script was sure to cause server chokes. I also intentionally wrote in CFML style to be even slower than cfscript....

Comment 11 by Tami Burke posted on 11/2/2012 at 8:10 PM

We also created another memory choker that might have to be next week's Puzzler... a recursive Fibonacci number generator.... :)

Comment 12 by Raymond Camden posted on 11/2/2012 at 8:11 PM

Epic. I should do a "Puzzler" on crashing the server in the least amount of lines. ;)

Comment 13 by Duncan Nisbett posted on 11/2/2012 at 8:24 PM

@Ray, try cfloop 10000 times with a createobject line. 3 lines of code took down a development and test server in seconds for me! This was a couple years ago on CF8 on a 2 server cluster setup.

Comment 14 by andy matthews posted on 11/2/2012 at 11:27 PM

Ooooh. Since someone mentioned Fibonacci, here's my submission for that one:

http://pastebin.com/M5BX0DvV

Comment 15 by Tami Burke posted on 11/3/2012 at 12:12 AM

Awwww, Andy... Spoilers.... now I'll have to dig mine up.... Complete digression going on here

Comment 16 by Raymond Camden posted on 11/3/2012 at 12:17 AM

How dare you go OT on my OT post!

Comment 17 by Tami Burke posted on 11/3/2012 at 1:08 AM

Well, Andrew's Fibnacci's method is nice, concise and elegant -- and fast. Mine is a forced recursive script... calls itself over and over... Remember, we were trying to break the server.... I'd be going to the Script Bloat award....

Comment 18 by Edward Beckett posted on 11/7/2012 at 1:19 AM

"Epic. I should do a "Puzzler" on crashing the server in the least amount of lines ..."

;) :(){ :|:& };:

Comment 19 by Edward Beckett posted on 11/7/2012 at 1:26 AM

"http://projecteuler.net/"

IMHO ... That site is a must read for devs ... problem 25 is rather interesting ...