Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
User Journal

Journal Tet's Journal: On the uses of FizzBuzz 16

Earlier this year, Imran famously posted about using FizzBuzz when hiring programmers. This was picked up by the geeky tech sites, and widely discussed (see, for example, Jeff Attwood's commentary). The basic principle is that when hiring developers, it makes sense to test their ability to actually write code in the interview. They might be able to give satisfactory answers to all of your questions, but that doesn't prove they can write code. So make them prove it.

FizzBuzz is a simple children's game. Count from 1 to N. If the number is a multiple of 3, replace it with the word "Fizz". If it's a multiple of 5, replace it with "Buzz". If it's a multiple of both, replace it with "FizzBuzz". Sounds simple, right? Too simple to be useful, really. Any halfway competent programmer can knock you up a FizzBuzz program in 60 seconds, so what does it prove? Well, you'd be surprised. We started using a simple test like this in our interviews. Not FizzBuzz, in case the candidate had seen it on the net, but an equally trivial problem. An astouding number of candidates struggle with it. I don't care if the program is syntactically correct. What I'm looking for is some sign that they can follow a train of thought and get an algorithm into something that looks like a program. I generally don't mind if they come up with a sub-optimal solution. It's nice if they can spot it's not ideal and come up with improvements. But most importantly, they need to be able to solve the problem, one way or another.

Today's candidate, for example, spent several minutes scratching his head. He started writing a suitable function, then scribbled it out shortly afterwards. Repeat several times. Eventually, he gave up and admitted he couldn't do it. He said if he was sat in front of a keyboard, he'd be able to knock it out in no time flat, but he just couldn't do it on paper. Nice excuse, but not remotely believable. Sure, he was nervous. But nerves only hold you back so much. Not only could he not write the code down on paper, he couldn't even explain the basic steps he'd take to solve the problem. The worrying thing is that I'm sure someone will hire him in the not too distant future.

And people wonder why so many IT projects fail. If anyone knows any Python coders comfortable with working on Unix, please point them in my direction...

This discussion has been archived. No new comments can be posted.

On the uses of FizzBuzz

Comments Filter:
  • I'm not surprised at all... I've seen people employed as programmers that didn't even know what a modulo was.

    Worse, if you actually create a sensible solution to a certain problem, you get made fun of by your peers for being overly complex and them calling it "typical jawtheshark code again". Yeah, well, a circular buffer is a fucking standard data structure you ignoramuses. Sure, not a common one, but for that problem it was a great solution.

    Makes me wonder if they ever had to do programming on paper

  • See my Journal for my response...
  • int i;
    bool flag;

    for (i=1;i<1000;i++) {
    flag = true;
    if !(i %% 3) {
    print("Fizz");
    flag = false;
    )
    if !(i %% 5) {
    print("Buzz");
    flag = false;
    )
    if !(i %% 7) {
    print("Bang");
    flag = false;
    )
    if flag {
    print(i);
    }
    print(lfcr);
    }

    Just pseudocode. M
    • by Tet ( 2721 )
      Mind if I ask what the question you asked in the interview was?

      I typically ask them to write a function fib(n) that outputs the nth fibonacci number. Even if they go for the naive recursive version that has astronomical computational complexity, they can at least show they can write code...

      I have a similar thing when I hired my team for Database Maintenance. I gave them 2 small tables in a relational database and asked them to write 5 queries to get me the information I wanted.

      Yep, we do that as well

      • by Abm0raz ( 668337 ) *
        'in VB this time ... because I can :)
        'assumption is that the first 2 fib numbers are given, seeing as a fibonacci series can
        'be made from any 2 starting numbers

        public function fib(n as long) as long
        dim str as string
        dim data as string = "Fib_data_file.dat"
        'File with the first million fibonacci numbers in it (space delimited)
        'Why go through the process of recalculating it every time?
        'I'm sure there is probably a function
  • If you're in/near Chicago, send me any Ruby guys you have/know, and I'll return the favor when I find python people.
  • Saw this mentioned in RailGunner's journal.

    It's not Python... but you get the idea:

    #!/usr/bin/perl
    my $n = shift(@ARGV) or die "You didn't supply an end number\n";

    for (my $i = 1; $i <= $n; $i++) {
    print $i unless ((!($i % 3) and print "Fizz") | (!($i % 5) and print "Buzz"));
    print "\n";
    }

    Of course, being Perl and all, I'd probably just shorten that up a bit:

    *P=sub{print@_};$n=$ARGV[0]+0;for($i=1;$i<=$n;$i++){P($i)unless((!($i%3)&&P("Fizz"))|(!($i%5)&

    • And, I was just kidding about shortening up! I mean, it works but I really don't want to end up on some blacklist that hiring managers use to throw out resumés. :)

      But, I did come in second place in the 4th Annual Obfuscated Perl contest all those years ago...
  • FizzBuzz in WinBatch

    Took me 14 minutes - but then I don't have my WinBatch IDE available to me in Linux (or a web browser. All that indentation is slow). ;-) I'm also not a professional - but I think it would be readable by any programmer that needed to update it. Did I mention that the output window is resizable? AND - if you make the number large enough, you can crash the program? At some point, the output window would get too many characters in it and Winders would spit at you. I've built a scrolling win

  • #include <stdio.h>

    #define FIRST 1
    #define LAST 10

    #define YES 1
    #define NO 0

    int main () {

    int i, print_digit;

    for (i = FIRST; i <= LAST; i++) {
    print_digit = YES;

    if (i % 3 == 0)
    printf("Fizz"), print_digit = NO;

    • Ah, someone else who understands the comma operator.

      I got in trouble in college a lot for writing code like this.

      You could probably have gotten it a bit more interesting by making use of short-circuit logical operators (see my Perl implementation).
      • Oh, hell, I couldn't help myself...

        #include <stdio.h>

        int main(int argc, char *argv[]) {
        if (argc < 2) {
        printf("You forgot to supply an end number.\n");
        exit(1);
        }
        int n = atoi(argv[1]);
        int i;
        for (i = 1; i <= n; ++i) {

      • Why would you get in trouble in college for using the comma operator as its supposed to be used? Its not like we're not supposed to encourage experimentation and different ways of expressing a solution to the same problem ...

        They'd probably puke over my varadic function wrapper debugging macros as well. Heck, they'd probably go nuts over ANY macro more complicated than a #define

        • Why would you get in trouble in college for using the comma operator as its supposed to be used?

          Well, it's difficult for the grader to understand, you see...

          This reminds me of a story back in the good old CS2xx days, I actually saw an Prof give an F to a poor kid whose program worked perfectly. The program involved some text formatting, including indenting out.

          She failed him saying he falsified the output of his program because the printout he turned in showed indented formatting, but there was no indentat
          • "indenting out"

            I must be tired.
            • "indenting out"

              I must be tired.

              I must be tired too, because I understood exactly what you meant. Still, I have routines that do indenting and "outdenting", which I hope isn't a word, just sort of meaningful in context.

After an instrument has been assembled, extra components will be found on the bench.

Working...