Tuesday, January 10, 2012

FizzBuzz

I recently discovered Codeacademy which is a great on-line learning resource for up and coming programmers. The most recent lesson involved solving FizzBuzz.

From the Codeacademy site:

FizzBuzz is a children's game where you count from 1 to 20. Easy, right?
Here's the catch: instead of saying numbers divisible by 3, say "Fizz". And instead of saying numbers divisible by 5, say "Buzz". For words divisible by both 3 and 5, say "FizzBuzz".
"1, 2, Fizz, 4, Buzz"...and so forth
Sounds easy enough - and yeah, I did find it pretty easy - I passed the course pretty easily (actually, I messed myself up thinking I was stuck by trying to solve the whole puzzle on their first step and they were breaking it up).

Apparently the FizzBuzz problem is a common hiring technique for folks looking to hire programmers, and I found where Jeff Atwood at Coding Horror has blogged about it a couple of times.

The quiz at Codeacademy had you solving it in JavaScript, but I went ahead and solved in Ruby and Python as well.

JavaScript:


Ruby:



Python:


No comments:

Post a Comment