weblog.masukomi.org

mah-soo-koh-me

 

FizzBuzz Rethink March 9, 2007

Filed under: Uncategorized — masukomi @ 12:00 am

Or maybe overthink would be more appropriate….

[UPDATE] I’ve written a followup about why an over-thought solution like the one proposed here can be / is a good thing. And just to be blazingly, obviously, painfully clear on the matter. I donot think that every problem should be over-thought to the degree I took this. My solution represents a crazy amount of code for such a small problem. It’s intended as an example of how I’d mentally approach a real and complex problem presented by a client.

The FizzBuzz test was conceived by Irman and posted here:
http://tickletux.wordpress.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/

It was to be used as a method for weeding out applications for developer
positions who couldn’t code anything and the original test instructions
were to:

Write a program that prints the numbers from 1 to 100. But for
multiples of three print “Fizz” instead of the number and for the multiples of
five print “Buzz”. For numbers which are multiples of both three and five print
“FizzBuzz”.

ANY developer should be able to write a solution to this and many did
in the comments of the original post and other posts that referenced it.
Unfortunately, as a number of bloggers pointed out, many of the people who
rushed to post solutions GOT IT WRONG! Mostly this was a result of just not
reading those three sentences carefully enough. I know, you’d think you
wouldn’t have to re-read those…

The solutions people were posting were inadvertently providing a classic
example of what’s wrong with how so many developers approach professional
software projects, which means that FizzBuzz is a better interview test than
anyone seems to realize. How a person approaches this problem for an
interview
is a great example of how they’ll approach other problems
they’re faced with should you decide to hire them.

I’ve been coding professionally for over a decade now and along the way I’ve
learned a number of things; things that I’d like to see addressed either in
code or by the questions an interviewee asks in response to the test. So lets
set the stage for something a little different.

First, we’re going to assume that it’s been explained that the FizzBuzz test
is based upon a children’s game of the same name.

In this game a group of children sit around in a group and say each
number in sequence, except if the number is a multiple of three (in which case
they say “Fizz”) or five (when they say “Buzz”). If a number is a multiple of
both three and five they have to say “Fizz-Buzz”.

Second, you have to remember that this is for an interview so the
response should not only display that they CAN code but, hopefully, give an
idea of how they’d approach the task of writing software for one of the
interviewer’s clients because if someone’s hiring you to code then there’s a
client (even if it happens to be the same company). Seeing if the interviewee
can make this logical leap without being told is another part of the test.

Third, after explaining the game the test is based on and with the assumption
that the person knows this is for an interview use the same instructions.

Click here to see my solution or pretend you’re an interviewee and write something to impress then see how our solutions compare.

 

Leave a Reply