FizzBuzz

Did you ever play FizzBuzz? If you didn’t, it’s a drinking game. That’s how I learned it, anyway.

It’s a counting game, and the rules are simple enough. Everyone sits in a circle and takes it in turn to say the next number, starting from one and ending at 100. The catch is that if the number is divisible by three the player says Fizz instead of the number, and if the number is divisible by five the player says Buzz. If the number is divisible by three and five the player says FizzBuzz. The penalty for miscounting, mis-fizzing or mis-buzzing is, predictably, a drink. Easy? Surprisingly not, and really rather hard after a skinful.

It’s also a game that’s popular with interviewers as a programming assignment to weed out applicants who are non-programming chancers.

A friend sent me an email that amused me greatly the other day. It’s the solution to FizzBuzz, but Enterprise quality code. You can download it here: https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

It’s a joke, but (sadly) there’s more than a grain of truth in it.

For completeness, here’s my answer (in C, natch). I’d be very interested to here from anyone who has a faster, more efficient, solution.

#include <stdio.h>
int main() { 
    for (int i=1; i<=100; i++) 
        ((i%3!=0)&&(i%5!=0))?printf("%d\n",i):printf("%s%s\n",(i%3==0)?”Fizz":"",(i%5==0)?”Buzz":"");
}
CategoriesUncategorised

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.