FizzBuzz

buzz

I’ve read some posts over the past few days about FizzBuzz.  Just for those who don’t know, it is a programming challenge one might challenge an interviewee with.  Some people I’ve read say it is hard.  This guy had a good idea to do it then throw the people into a meeting to see how they react to changing requirements.  Personally, this is why I try to “over think” things.

It isn’t hard.  Why?  Here’s some pseudocode:

out = “”
for x = 1 to 100:
  if x mod 3 = 0:
    out = “Fizz”
  if x mod 5 = 0:
    out = out + “Buzz”
  print out

That’s it.  2 if statements and some string manipulation.  If you wanted to make it more expandable, do something like this:

min = 1
max = 100
test1 = 3
test2 = 5
out = “”
out1 = “Fizz”
out2 = “Buzz”

for x = min to max:
  if x mod test1:
    out = out1
  if x mod test2:
    out = out + out2
  print out

You could also expand on this with a structure like an array for the loop, etc…  It depends on how much one wants to engineer it and make it expansible.  It isn’t hard.  Frankly, I don’t think I’d hire someone who couldn’t do it.  The reason I like the code review/changing requirements test is seeing how people think under pressure and modifying something they’ve worked on.

Image from Sean MacEntee via flickr

Leave a Reply

Your email address will not be published. Required fields are marked *