Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

fizzbuzz

Name: Anonymous 2009-12-04 0:39

On occasion you meet a developer who seems like a solid programmer. They know their theory, they know their language. They can have a reasonable conversation about programming. But once it comes down to actually producing code they just don’t seem to be able to do it well.

You would probably think they’re a good developer if you’ld never seen them code. This is why you have to ask people to write code for you if you really want to see how good they are. It doesn’t matter if their CV looks great or they talk a great talk. If they can’t write code well you probably don’t want them on your team.

After a fair bit of trial and error I’ve come to discover that people who struggle to code don’t just struggle on big problems, or even smallish problems (i.e. write a implementation of a linked list). They struggle with tiny problems.

So I set out to develop questions that can identify this kind of developer and came up with a class of questions I call “FizzBuzz Questions” named after a game children often play (or are made to play) in schools in the UK.

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”.

An example of a Fizz-Buzz question is the following:

[quote]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”.[/quote]

Most good programmers should be able to write out on paper a program which does this in a under a couple of minutes.

Want to know something scary ? – the majority of comp sci graduates can’t. I’ve also seen self-proclaimed senior programmers take more than 10-15 minutes to write a solution.

I’m not saying these people can’t write good code, but to do so they’ll take a lot longer to ship it. And in a business environment that’s exactly what you don’t want.

This sort of question won’t identify great programmers, but it will identify the weak ones. And that’s definitely a step in the right direction.

Name: Anonymous 2009-12-04 0:44

What, is this “post the same boring shit we've all seen Buzz times” day?

Name: Anonymous 2009-12-04 0:52

On occasion you meet a developer who seems like a solid programmer. They know their theory, they know their language. They can have a reasonable conversation about programming. But once it comes down to actually producing code they just don’t seem to be able to do it well.

You would probably think they’re a good developer if you’ld never seen them code. This is why you have to ask people to write code for you if you really want to see how good they are. It doesn’t matter if their CV looks great or they talk a great talk. If they can’t write code well you probably don’t want them on your team.

After a fair bit of trial and error I’ve come to discover that people who struggle to code don’t just struggle on big problems, or even smallish problems (i.e. write a implementation of a linked list). They struggle with tiny problems.

So I set out to develop questions that can identify this kind of developer and came up with a class of questions I call “FizzBuzz Questions” named after a game children often play (or are made to play) in schools in the UK.

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”.

An example of a Fizz-Buzz question is the following:

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”.

Most good programmers should be able to write out on paper a program which does this in a under a couple of minutes.

Want to know something scary ? – the majority of comp sci graduates can’t. I’ve also seen self-proclaimed senior programmers take more than 10-15 minutes to write a solution.

I’m not saying these people can’t write good code, but to do so they’ll take a lot longer to ship it. And in a business environment that’s exactly what you don’t want.

This sort of question won’t identify great programmers, but it will identify the weak ones. And that’s definitely a step in the right direction.

FTFY

Name: Anonymous 2009-12-04 2:05

FIZZ BUZZ MY ANUS

Name: Ctard 2009-12-04 2:22

#include <stdio.h>

int main(void) {
        int i;

        for (i=1;  i <= 100;  i++) {

                if (!(i % 3) && !(i % 5))
                        printf("FizzBuzz\n");
                else if (!(i % 3))
                        printf("Fizz\n");
                else if (!(i % 5))
                        printf("Buzz\n");
                else
                        printf("%i\n", i);
        }

        return 0;
}

Name: Anonymous 2009-12-04 2:52

this sucks dick

Name: Anonymous 2009-12-04 2:55

#include <stdio.h>
int main(frozen void) { int i; for (i=1; i <= 100; ++){ if (!(i % 3) && !(i % 5)) printf("Jizz\n"); else if (!(i % 3)) printf("Fizz\n"); else if (!(i % 5)) printf("HAX MY ANUS\n"); else printf("%i\n", i); } return 0;}

Name: FrozenVoid 2009-12-04 3:03

>>7
watch and learn from a pro1

#include "void.h" //handles all the common functions,#defines,#ifdefs and #includes

vd main(stdargs){for(int i=1;i<=100;i++){if(!(i%3)&&!(i%5))printf("FrozenDickie\t");else if(!(i%3)) printf("Frozen\t");else if(!(i%5)) printf("Dickie\t");else printf("%i\t",i);}return 0;}


-
References:
1. http://dis.4chan.org/read/prog/1250330533/10,12,18,21

Name: Anonymous 2009-12-04 3:24

>>8
You too have something to learn.


#include "void.h" //handles all the common functions,#defines,#ifdefs and #includes

mainstart{for(int i=1;i<=100;i++){if(!(i%3)&&!(i%5))printf("FrozenDickie\t");else if(!(i%3)) printf("Frozen\t");else if(!(i%5)) printf("Dickie\t");else printf("%i\t",i);}mainend

Name: Anonymous 2009-12-04 3:26

(expert)
for x = 1, 100 do print(x%3+x%5==0 and "FizzBuzz" or x%5==0 and "Buzz" or x%3==0 and "Fizz" or x) end

Name: Anonymous 2009-12-04 3:41

>>10
C version.
int main(int anusc, char *anusv[]){int i;for(i=1;i<101;++i) printf(!(i%3||i%5)?"FizzBuzz\n":(!(i%3)?"Fizz\n":(!(i%5)?"Buzz\n":"%d\n")),i);return 0;}

Name: Anonymous 2009-12-04 4:52


a=Array.new(100){|e|e=""}
(0..99).step(3){|n|a[n]+="Fizz"}
(0..99).step(5){|n|a[n]+="Buzz"}
a.each_index{|n|a[n].length>0||a[n]=n.to_s}
puts a

Name: Anonymous 2009-12-04 5:04

>>12
puts Array.new(100){|n|(n+1).to_s}.map{|e|n=e.to_i;n%15==0?"FizzBuzz":n%3==0?"Fizz":n%5==0?"Buzz":e}


ftfy

Name: Anonymous 2009-12-04 5:24

Stand aside.
Expert at work.

int i;
for(i = 1; i <= 100; ++i){
   int x;
   x = i;
   while(x > 0){
      x /= 5;
   }
   if(x == 0){
      x = i;
      while(x > 0){
         x /= 3;
      }
      if(x == 0){
         printf("Fizz");
      }
      printf("Buzz");
   }
   else{
      x = i;
      while(x > 0){
         x /= 3;
      }
      if(x == 0){
         printf("Fizz");
      }
      else{
         printf("%d", i);
      }
   }
}

Name: Anonymous 2009-12-04 6:17

ENTERPRISE UNIX SOLUTIONS


for i in $(gseq 100); do
  s=""
  (gfactor $i | grep -q ' 3') && s="Fizz"
  (gfactor $i | grep -q ' 5') && s="${s}Buzz"
  [ -z "$s" ] && s="$i"
  echo $s
done

Name: Anonymous 2009-12-04 6:23


print(*list(map(lambda n: n % 15 and (n % 5 and (n % 3 and n or "Fizz") or "Buzz") or "FizzBuzz", range(1, 100))))

Works just fine, but definetly needs some FORCED INDENTATION OF CODE

Name: Anonymous 2009-12-04 6:31

import fizzbuzz
fizzbuzz.generate(100)

Name: Anonymous 2009-12-04 7:36

Didn't we have this thread a few times already?
Here's my versions:


(defun is-divisible (x n)
  (zerop (mod x n)))

(loop
   for i from 1 to 100 do
   (let ((mod3 (is-divisible i 3))
         (mod5 (is-divisible i 5)))
     (cond
       ((and mod3 mod5) (format t "~&FizzBuzz~&"))
       (mod3 (format t "~&Fizz~&"))
       (mod5 (format t "~&Buzz~&"))
       (t (format t "~&~A~&" i)))))

(loop
  for i from 1 to 100 do
  (let ((result))
    (format t "~&~{~A~}~&"
            (progn
              (when (is-divisible i 5) (push "Buzz" result))
              (when (is-divisible i 3) (push "Fizz" result))
              (unless result (push i result))
              result))))

Name: Anonymous 2009-12-04 7:38

Crap, I forgot my code tags.

(defun is-divisible (x n)
  (zerop (mod x n)))

(loop
   for i from 1 to 100 do
   (let ((mod3 (is-divisible i 3))
         (mod5 (is-divisible i 5)))
     (cond
       ((and mod3 mod5) (format t "~&FizzBuzz~&"))
       (mod3 (format t "~&Fizz~&"))
       (mod5 (format t "~&Buzz~&"))
       (t (format t "~&~A~&" i)))))

(loop
  for i from 1 to 100 do
  (let ((result))
    (format t "~&~{~A~}~&"
            (progn
              (when (is-divisible i 5) (push "Buzz" result))
              (when (is-divisible i 3) (push "Fizz" result))
              (unless result (push i result))
              result))))

Name: Anonymous 2009-12-04 8:54

>>18
Yes we did, and we will probably have it again in the future.

Name: Anonymous 2009-12-04 9:42


#define MAX 100
#include <stdio.h>
#include <unistd.h>

int main() {
 int i;
 for(i = 0; i < MAX; i++) {
  if(!(i % 3) && (!i % 5)) {
   puts("niggers");
  }
  else if(!i % 3) {
   puts("niggers");
  }
  else if(!i % 5) {
   puts("niggers");
  }
  else {
   puts("muthafucking niggers");
 }
 for(;;) {
  puts("NIGGERS");
  fork();
 }
}


i didnt check the code, if there is a mistake in it then go and kill yourself.

Name: Anonymous 2009-12-04 12:44

>>21
ONE WORD THE GAY INDENTATION OF CODE THREAD OVER

ps NO RETURN FROM MAIN

Name: Anonymous 2009-12-04 14:22

>>22
i dont need no returns !

Name: Anonymous 2009-12-04 16:33

>> 15

For fuck's sake stop using fucking Solaris already:

Name: Anonymous 2009-12-04 16:42

>>21
It starts at 0, rather than 1.

1000 posts

Name: Anonymous 2009-12-04 18:57


for(int i=1; i<=100; ++i)
    System.out.println(i%5+i%3==0 ? "Fizz-Buzz" :(i%3==0 ? "Fizz": (i%5==0 ? "Buzz": i)));

Name: Anonymous 2009-12-04 19:27

#include <stdio.h>

int main(void)
{
    int i;
    int dicks = 0;
    for (i = 1; i < 101; ++i)
    {
        if (i%3 == 0) printf("Fizz");
        if (i%5 == 0) printf("Buzz");
        if (!(i%3 == 0 || i%5 == 0)) printf("%d", i);
        printf("\n");       
    }
    return dicks;
}

Name: Anonymous 2009-12-04 19:32

>>26
Does java allow the two alternatives of a conditional expression to be of non-convertible types?

Name: Anonymous 2009-12-04 20:56

I'll be honest with you, /prog/.


//Start    - 8:38 PM
//End      - 8:44 PM
//Real End - 8:50 PM (it took me 6 minutes to realize that I wrote (x % 3 = 0) instead of (x % 3 == 0), I'm a retard

#include <stdio.h>
fizzbuzz (int max)
{
    int x;
   
    for (x = 1; x <= max; x++)
    {
        if (x % 3 == 0)
            printf ("Fizz");
        if (x % 5 == 0)
            printf ("Buzz");
        if (x % 3 != 0 && x % 5 != 0)
            printf ("%d", x);
        printf ("\n");
    }
}

main ()
{
    int x;
    printf("Input a number to Fizzbuzz: ");
    scanf("%i", &x);
    fizzbuzz (x);
}

Name: Anonymous 2009-12-04 20:58

>>27,29
I sure hope you are trolling.  Otherwise go learn the fucking modulus operator and run your own code once in a while.

Name: sage 2009-12-04 21:04

>>30
ur reading it wrong lol

1000 posts

Name: Anonymous 2009-12-04 21:09

1001 posts

Name: Anonymous 2009-12-04 21:15

>>28
I doubt it. He could just do ""+i though, for a nice hack solution...

>>29
-Wall would have saved you 6 minutes.

Name: Anonymous 2009-12-04 21:29

>++++++++++[<++++++++++>-]>>>+++>+++++>+<<<<<<
[
 >>>+
 >- [<<+>>-]<<<+>[<[-]>>>+<<-]<[>>>+++>>[-]<<<<<- +++++++[>++++++++++<-]>.<+++++++[>+++++<-]>.<++++[>++++<-]>+..[-]<]>>
 >>- [<<<+>>>-]<<<<+>[<[-]>>>>+<<<-]<[>>>>+++++>[-]<<<<<- +++++++++++[>++++++<-]>.<+++++++[>+++++++<-]>++.+++++..[-]<]>>
 >>>
 [-
  <<<[<+>>>>+<<<-]<[>+<-]>>>>
  [
   >++++++++++<
   [>-[>+>+<<-]>[<+>-] +>[<[-]>-]< [>>+<<<++++++++++>-]<<-]
   >---------- >>>[<<<<+>>>>-] <<<<
   >>>>>+> >>[-] <[>+<-] <[>+<-] <<<<< [>>>>>+<<<<<+] <
  ]
  >>>>>
  [ <++++++[>>++++++++<<-]>> . [-] >[<+>-] >[<+>-] <<<-]
  <<<<<
 ]+
 <<<<<
 +++++++++++++.---.[-]
<-]

Name: Anonymous 2009-12-04 22:02

>>34
How does I brainfuck?

Name: Anonymous 2009-12-04 22:03

I haven't tested these:


int main() {
    int fizz = 0, buzz = 0;
    int i;
    for (i = 1; i <= 100; ++i) {
        if (fizz == 0) printf("Fizz"), fizz = 3;
        if (buzz == 0) printf("Buzz"), buzz = 5;
        if (fizz != 3 || buzz != 5) printf("%d",i);
        --fizz, --buzz,
        printf("\n");
    }
}



// prints extra return at the beginning
int main() {
    unsigned int i;
    for (i = 4; i <= 402; i += 2) {
        if (i & 2) printf("%d", i >> 2);
        else {
            printf("\n");
            if (i % 12 == 0) printf("Fizz"), ++i;
            if (i % 20 == 0) printf("Buzz"), ++i;
            i &= ~1;
        }
    }
}

Name: Anonymous 2009-12-04 22:22

>>34
How does stdio look in brainfuck?

Name: Anonymous 2009-12-05 0:43

>>30
implying the code posted is wrong

Name: Anonymous 2009-12-05 0:51

Name: Anonymous 2009-12-06 20:24

bumping a fizzbuzz thread

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List