Understand the program below…

March 30, 2007

…and you’ll be better than 99% of working programmers. At least, that’s what a recent digg article stated and then linked to this article. While I don’t really believe the numbers, I do believe that there are quite few “programmers” out there that do nothing but copy and paste code. But you and I won’t be one of those. We’ll walk through how to create this very simple (but maybe not for most?) program in Ruby. Let’s outline what it needs to accomplish:

This program, called FizzBuzz, needs to do the following for the numbers between 1 and 100: if the number is divisible by 5 and 3, print FizzBuzz. If the number is divisible by 5 only, print Fizz. If the number is divisible by 3 only, print Buzz. Otherwise, print the number itself. This reminds me of a drink…er…number game I used to play in college. Ok, so the hardest thing about writing this program is just understanding how the modulus operator works. Most languages have a mod command and in Ruby it happens to be %. The statement “x % y” would divide x by y and then return the remainder. So, to determine if a number is divisible by x, we check that when we mod it with x, the result is 0 (thus, no remainder). With this small piece of knowledge we can write the FizzBuzz program and break into the top 1% of programmers world-wide:

The Code

And that’s all there is to it. Ask any questions, otherwise enjoy and welcome to the top 1%.


2 Responses to “Understand the program below…”

  1. zakimirza Says:

    lol, this rlly is just stupid. I dont know whoever came up with this fizzbuzz thing. 99% of my class can do it in less than 5 minutes. And how can one base the whole programming paradigm on just a modulus operator. A good methematician will talk in terms of remainders etc. Only those who have never seen a p/q rational number and never done a division can think that. but neways.

  2. drewolson Says:

    As I stated in the article, I too believe this is an exaggeration. However, the point here is that there are professional programmers who are unable to complete this simple task. I certainly wasn’t implying that the entire programming paradigm is covered in the scope is this trivial task, it’s simply a bizarre observation that many so-called “software engineers” are unable to write this simple program.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: