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-10 10:28

>>121
Wanna fight about it?

Name: Anonymous 2009-12-10 10:29

>>122
I don't see anything to fight about.

Name: Anonymous 2009-12-10 12:03

>>122
+8 Susspoints for paying attention to the details.

That reminds me, where did 1 go?

Name: 121-kun 2009-12-10 13:09

>>124
Excuse me, >>122-san seems to have gotten my eight Susspoints.

Name: Anonymous 2009-12-10 13:32

I have OVER 1MILLION Susspoints in my offshore Sussbank Sussaccount

Name: Anonymous 2009-12-10 13:32

What do you mean? >>122-kun was supposed to get them. And this post of yours shows clearly that the prize should indeed be subtracted from your account.

Name: Anonymous 2009-12-10 13:53

hax my anus

Name: Anonymous 2009-12-10 14:18

>>128
i love ur retro-style

Name: Anonymous 2009-12-11 18:43

>>122
I don't see any ligature. It's fi (U+0066 U+0069), not (U+FB01).

Name: Anonymous 2009-12-11 21:22

>>37
How does a cudder look?

Name: Anonymous 2009-12-11 21:40

ᶠᶦᶻᶻᵇᵕᶼᶼᶠᶦᶻᶻᵇᵕᶼᶼᶠᶦᶻᶻᵇᵕᶼᶼ

Name: Anonymous 2009-12-11 21:49

ᶠᶦᶻᶻᵇᵕᶼᶼ

Name: Anonymous 2009-12-12 0:02

Buzz my anus

Name: Anonymous 2009-12-29 2:39

:0 j0 + j1 %$0,3 =0 [ p"Fizz" ] j2 %$0,5 =0 [ p"Buzz" g1 ] j1 !0 [ g2 ] :1 j0 =100 [ g99 ] p"\n" g0 :2 j2 !0 [ p$0 g1 ] :99


Expert programming language.

Name: Anonymous 2009-12-29 4:33

1+1+1+1+1+1+1+1+1+1+1+1= _____________




























http://www.cafepress.com/digitalnasties

Name: Anonymous 2009-12-29 7:36

I managed to do it in 5 minutes in Java, not my best code ever and I'm only a 1st year student of computer sciences. My code:

public class FizzBuzz
{
   public static void main(String[] args)
     {
    for (int i = 1; i <= 100; ++i)
      {
         if (i % 3 == 0 && i % 5 == 0)
           {
          System.out.println("FizzBuzz");
           }
         else if (i % 3 == 0)
           {
          System.out.println("Fizz");
           }
         else if (i % 5 == 0)
           {
          System.out.println("Buzz");
           }
         else
           {
          System.out.println(i);
           }
      }
     }
}

Name: Anonymous 2009-12-29 8:23

#include <iostream>
using namespace std;

int divideByThree(int x);
int divideByFive(int x);

int main() {
    int haxus = 1;
    for (haxus; haxus <= 100; haxus++) {
        if (divideByThree(haxus) == 0 && divideByFive(haxus) != 0) {
             cout << "Fizz\n";
             }
        else if (divideByThree(haxus) != 0 && divideByFive(haxus) == 0) {
             cout << "Buzz\n";
             }
        else if (divideByThree(haxus) == 0 && divideByFive(haxus) == 0) {
             cout << "FizzBuzz\n";
             }
        else {
             cout << haxus << "\n";
             }
        }
    return 0;
}

int divideByThree(int x) {
    return x % 3;
}

int divideByFive(int x) {
    return x % 5;
}

Name: Anonymous 2009-12-29 8:27

>>138
(≖‿≖ )

Name: Anonymous 2009-12-30 0:42

/* 12:38:53 AM */


int main() {
   
    int i;
    for (i = 1; i<=100; i++) {
       
        if (!(i%15))
            printf("JizzFizz\n");
        else if (!(i%3))
            printf("Jizz\n");
        else if (!(i%5))
            printf("Fizz\n");
        else
            printf("%d\n", i);
       
       
    }
   
   
}

/* 12:41:22 AM */

Name: Anonymous 2009-12-30 7:55

/* 14:54:01 */

>>140
You're implementation sucks.

/* 14:54:12 */

Name: Anonymous 2009-12-30 11:02

/* 11:02:26 AM */

You're grammar sucks.

/* 11:02:35 AM */

Name: Anonymous 2009-12-30 14:40

hey guys im sweden

-module(fb).
-export([fb/0]).

fb() -> fibu(100).

fibu(1) -> 1;
fibu(N) when (N rem 3) == 0, (N rem 5) == 0  -> io:format("Fizz-Buzz~n",[]),
                                                fibu(N-1);
fibu(N) when (N rem 3) == 0                  -> io:format("Fizz~n",[]),
                                                fibu(N-1);
fibu(N) when (N rem 5) == 0                  -> io:format("Buzz~n",[]),
                                                fibu(N-1);
fibu(N)                                      -> io:format("~w~n",[N]),
                                                fibu(N-1).

Name: Anonymous 2009-12-30 23:25

(define fizzbuzz
  (λ(ceiling)
    (let ((fb (list 'n 'n 'fizz 'n 'buzz 'fizz 'n 'n 'fizz 'buzz 'n 'fizz 'n 'n 'fizzbuzz)))
      (let L ((cycle fb)
              (n 1))
        (if (= ceiling n)
            empty
            (let ((cycle (if (empty? cycle) fb cycle)))
              (let ((val (if (eq? 'n (car cycle)) n (car cycle))))
                (cons val (L (cdr cycle) (+ 1 n))))))))))

Name: Anonymous 2009-12-31 0:10

>>144
I rate your post -1 because it uses a capital letter in scheme. Disgusting. NO CAPITAL LETTERS!

Name: Anonymous 2009-12-31 0:13

99.9% of Computer Science papers are descriptions of efficient algorithms/data structures that are impractical to implement.

Name: Anonymous 2009-12-31 8:47

>They know their theory, they know their language.
It is better if they know mathematics and algorithmics. After, the language is less important.

Here some poeple check that x is divisible by 3 and is divisible by 5. It is faster to check that x is divible by 15.

Name: Anonymous 2009-12-31 8:48

CHECK MY ANUS

Name: Anonymous 2009-12-31 12:42

>>145
Thank you for your constructive criticism, I will work on it!!

Name: Anonymous 2009-12-31 13:32

>>147
Don't help them!!

Name: Anonymous 2010-01-04 5:01


#include <stdlib.h>
int main(){char*f="Fizz",*b="Buzz",i;for(i=0;i<101;i++)printf((i%3)?((i%5)?"%3$d\n":"%2$s\n"):((i%5)?"%s\n":"%s%s\n"),f,b,i);}

Name: Anonymous 2010-01-04 5:18

>>151

#include <stdlib.h>
int main(){char*f="Fizz",*b="Buzz",i;for(i=0;i<101;i++)printf(i%3?i%5?"%3$d\n":"%2$s\n":i%5?"%s\n":"%s%s\n",f,b,i);}

Name: Anonymous 2010-01-04 5:33

>>152

#include <stdlib.h>
int main(){char*f="Fizz",*b="Buzz\n",i;for(i=0;++i<101;)printf(i%3?i%5?"%3$d\n":b:i%5?"%s\n":"%s%s",f,b,i);}

Name: Anonymous 2010-01-04 7:24

>>153
i;main(){while(i++<100)printf("%s%s%.d\n",i%3?"":"Fizz",i%5?"":"Buzz",i%5&&i%3?i:0);}

Name: Anonymous 2010-01-04 8:42

>>154
#include <stdlib.h>
i;main(){while(i++<100)printf("%s%s%.d\n",i%3?"":"Fizz",i%5?"":"Buzz",i%15?i:0);}

Name: Anonymous 2010-01-04 10:02

>>155
#include <sys/mman.h>
main(){facepalm();}

Name: Anonymous 2010-01-04 11:21

int main(){return -1;}

Name: Anonymous 2010-01-04 12:08

i%3?"":"Fizz",i%5?"":"Buzz",i%15?i:0)
"1
"2
"Fizz3
"4
"Buzz5"
I might be misinterpreting the printf (I've always been bad about that) but this is not what the instructions ask.

Name: Anonymous 2010-01-04 14:41

MISINTERPRET MY ANUS

Name: Anonymous 2010-01-04 15:47

#include <fizzbuzz.c>

Name: Anonymous 2010-01-04 23:16

>>160
You should only include headers, not source files.

Name: Anonymous 2010-01-04 23:46

>>161
Bollocks. Tons of great reasons to use #include to include source files.

Name: Anonymous 2010-01-05 0:25

>>162
your an idiot hes right

Name: Anonymous 2010-01-05 0:26

>>162
Such as:

- templates

That's it. It's at best a workaround for limitations in C++. So many fucking hacks for backwards compatibility with C...

Name: Anonymous 2010-01-05 10:17

>>164
Come to think of it, do you guys believe that if it wasn't Stroustrup's intention to keep backward compatibility with C, would the C++ be any good?

Name: Anonymous 2010-01-05 10:18

>>165
What would C++ be then? Wasn't it created from the start with such intentions?

Name: Anonymous 2010-01-05 11:02

>>165
Of course not. The reason Sepples failed isn't because of backward compatibility. It's because Bjornie Stripstrap is a moron.

Name: Anonymous 2010-01-05 11:10

>>167
Sepples failed
*sigh*

Name: Anonymous 2010-01-05 12:01

>>168
THAT WHAT PRETENTIOUS TEENAGERS ACTUALLY BELIEVE!

Name: Anonymous 2010-01-05 12:31

>>167

The reason Sepples failed isn't because of backward compatibility.
But of course! Actually, that's the reason it's used at all.

And so, history repeats itself.

Name: dasuraga !8GgBtN/zr. 2010-01-05 14:08

what's with people and hating c++? It's syntaxically pretty ugly, but not at all unusable(at least I enjoy using it more than it's "safer" C-likes)

Name: Anonymous 2010-01-05 14:24

>>171
That's because you're either retarded or know no other languages. That's related to the discussion; it's my way of saying, "Have you read your FQA today?"

Name: Anonymous 2010-01-05 14:30

>>172
Yeah let's get back to hating proper /prauge/ style. Hate on FOIC and retarded ass Lispers and Haskallers

Name: Anonymous 2010-01-05 15:13

>>173
dont forget the enterprise

Name: Anonymous 2010-01-05 15:13

Any one of those, even FIOC, is better than Sepples.

Name: Anonymous 2010-01-05 15:15

>>174
dude, startrek is okay

Name: Anonymous 2010-01-05 23:11

fizzBuzz x | mod x 15 == 0 = "FizzBuzz " | mod x 5  == 0 = "Fizz " | mod x 3  == 0 = "Buzz " | otherwise = show x ++ " "
main = print [x | x <- [1..100], x <- fizzBuzz x]

Name: Anonymous 2010-01-06 0:15

EVERYONE, STEP THE FUCK BACK

#include <iostream>
int main()
{
std::cout << 1 << endl;
std::cout << 2 << endl;
std::cout << "Fizz" << endl;
std::cout << 4 << endl;
std::cout << "Buzz" << endl;
std::cout << "Fizz" << endl;
std::cout << 7 << endl;
std::cout << 8 << endl;
std::cout << "Fizz" << endl;
std::cout << "Buzz" << endl;
std::cout << 11 << endl;
std::cout << "Fizz" << endl;
std::cout << 13 << endl;
std::cout << 14 << endl;
std::cout << "FizzBuzz";
std::cout << 16 << endl;
std::cout << 17 << endl;
std::cout << "Fizz" << endl;
std::cout << 19 << endl;
std::cout << "Buzz" << endl;
std::cout << "Fizz" << endl;
std::cout << 22 << endl;
std::cout << 23 << endl;
std::cout << "Fizz" << endl;
std::cout << "Buzz" << endl;
std::cout << 26 << endl;
std::cout << "Fizz" << endl;
std::cout << 28 << endl;
std::cout << 29 << endl;
std::cout << "FizzBuzz" << endl;
std::cout << 31 << endl;
std::cout << 32 << endl;
std::cout << "Fizz" << endl;
std::cout << 34 << endl;
std::cout << "Buzz" << endl;
std::cout << "Fizz" << endl;
std::cout << 37 << endl;
std::cout << 38 << endl;
std::cout << "Fizz" << endl;
std::cout << "Buzz" << endl;
std::cout << 41 << endl;
std::cout << "Fizz" << endl;
std::cout << 43 << endl;
std::cout << 44 << endl;
std::cout << "FizzBuzz" << endl;
std::cout << 46 << endl;
std::cout << 47 << endl;
std::cout << "Fizz" << endl;
std::cout << 49 << endl;
std::cout << "Buzz" << endl;
std::cout << "Fizz" << endl;
std::cout << 52 << endl;
std::cout << 53 << endl;
std::cout << "Fizz" << endl;
std::cout << "Buzz" << endl;
std::cout << 56 << endl;
std::cout << "Fizz" << endl;
std::cout << 58 << endl;
std::cout << 59 << endl;
std::cout << "FizzBuzz" << endl;
std::cout << 61 << endl;
std::cout << 62 << endl;
std::cout << "Fizz" << endl;
std::cout << 64 << endl;
std::cout << "Buzz" << endl;
std::cout << "Fizz" << endl;
std::cout << 67 << endl;
std::cout << 68 << endl;
std::cout << "Fizz" << endl;
std::cout << "Buzz" << endl;
std::cout << 71 << endl;
std::cout << "Fizz" << endl;
std::cout << 73 << endl;
std::cout << 74 << endl;
std::cout << "FizzBuzz" << endl;
std::cout << 76 << endl;
std::cout << 77 << endl;
std::cout << "Fizz" << endl;
std::cout << 79 << endl;
std::cout << "Buzz" << endl;
std::cout << "Fizz" << endl;
std::cout << 82 << endl;
std::cout << 83 << endl;
std::cout << "Fizz" << endl;
std::cout << "Buzz" << endl;
std::cout << 86 << endl;
std::cout << "Fizz" << endl;
std::cout << 88 << endl;
std::cout << 89 << endl;
std::cout << "FizzBuzz" << endl;
std::cout << 91 << endl;
std::cout << 92 << endl;
std::cout << "Fizz" << endl;
std::cout << 94 << endl;
std::cout << "Buzz" << endl;
std::cout << "Fizz" << endl;
std::cout << 97 << endl;
std::cout << 98 << endl;
std::cout << "Fizz" << endl;
std::cout << "Buzz" << endl;
return 0;
}

Name: Anonymous 2010-01-06 0:27

>>177,178
[code] tags, please.

Name: Anonymous 2010-01-06 0:53

#include <iostream>
using std::cout;
using std::endl;

const int max = 100;

template <int val = 1>
struct Buzzer {
  Buzzer() {
    if (val % 15 == 0)
      cout << "fizzbuzz";
    else if (val % 3 == 0)
      cout << "fizz";
    else if (val % 5 == 0)
      cout << "buzz";
    else
      cout << val;
    cout << endl;
    if (val < max)
      Buzzer<val + 1>();
  }
};

template <>
struct Buzzer<max + 1> {};

int main() {
  Buzzer<>();
}


Did you know regular (non-class) functions can't have default template arguments? I didn't. I was also surprised to find that GCC's default template depth is 500.

I fucking hate sepples

Name: Anonymous 2010-01-06 1:06

Whoops, I left in that bogus line if (val < max) which doesn't actually do anything. Doesn't break it though.

Name: Anonymous 2010-01-06 3:06

>>177
What language is that anyway?

Name: Anonymous 2010-01-06 4:09

>>182
haxall

Name: Anonymous 2010-01-06 4:47

>>183
HAX ALL MY ANII

Name: Anonymous 2010-01-06 12:37

>>178

~ % g++ ">>178.cpp"
>>178.cpp: In function ‘int main()’:
>>178.cpp:4: error: ‘endl’ was not declared in this scope

Name: Anonymous 2010-01-06 18:40

This is currently the highest rated thread on Reddit, and the top 2 posts also have over 1000 upvotes each

http://www.reddit.com/r/funny/comments/alwm7/my_9_year_old_cousin_and_i_are_playing_a_game_of/

* Hilarity ensues!

Name: Anonymous 2010-01-06 21:31

>>185
FFFFFUUUUU-
my bad, forgot std::endl on each endl thing. using namespace std is such a bad habit =[


feels bad man

Name: Anonymous 2010-01-06 21:49

>>187
Something wrong with using std::endl;?

Name: Anonymous 2010-01-06 22:45

only a fool would dare give their function a name that conflicts with the standard fucking library

Name: Anonymous 2010-01-07 1:13

>>186
Reddit is down for maintenance.

Name: Anonymous 2010-01-07 1:16

>>190
Occasionally sites will tempporarily go down so the admins can perform kernel updates, moving databases, updating caches, etcetera. The best thing to do is spend time with family and friends.

Name: Anonymous 2010-01-07 1:20

>>191
Hi, been a long time lurker on this board.. but I feel I have to speak out at this moment.
 
Never on The 4Chan Programming board have I seen someone be so horrible and with no provocation, utterly appalling.
 
That was uncalled for and just plain rude.

Name: Anonymous 2010-01-07 14:03

>>190
And nothing of value was lost.

Name: Anonymous 2010-01-07 15:00

>>191
The best thing to do is spend time with family and friends.
spend time with family and friends.

you dont spend much time on /prog/, eh?
the proper answer would have been: programming.

Name: Anonymous 2010-01-08 2:12

>>194
you dont spend much time on /prog/, eh?
the proper answer would have been: anus haxing.

Name: Anonymous 2010-02-22 16:57

>>154
Bump to see if someone can get it in less characters.

Name: Anonymous 2010-02-22 17:06

fizz get

Name: Anonymous 2010-02-22 17:31

buzz set

Name: Anonymous 2010-02-22 17:31

fizzbuzz GET

Name: Anonymous 2010-02-22 17:50

>>199-200
Doing it WRONG

Name: Anonymous 2010-02-22 22:25

class FizzBuzz {
    public static void main(String[] args){

        int isNum =0;

        for (int i =0; i <100; i++) {
            isNum += (i % 3==0) ? 3 : 0;
            isNum += (i % 5==0) ? 5 : 0;
            switch (isNum) {
                case 3: System.out.println("Fizz: "+ i); isNum = 0; break;
                case 5: System.out.println("Buzz: "+ i); isNum = 0; break;
                case 8: System.out.println("FizzBuzz"+ i); isNum = 0; break;
                default: System.out.println(i); isNum = 0; break;
            }
        }
    }
}

Name: Anonymous 2010-02-22 22:32

class FizzBuzz {
    public static void main(String[] args){

        int isNum =0;

        for (int i =0; i <100; i++) {
            isNum += (i % 3==0) ? 3 : 0;
            isNum += (i % 5==0) ? 5 : 0;
            switch (isNum) {
                case 3: System.out.println("Fizz: "+ i); isNum = 0; break;
                case 5: System.out.println("Buzz: "+ i); isNum = 0; break;
                case 8: System.out.println("FizzBuzz"+ i); isNum = 0; break;
                default: System.out.println(i); isNum = 0; break;
            }
        }
    }
}

Name: Anonymous 2010-02-22 22:33

[code]
class FizzBuzz {
    public static void main(String[] args){

        int isNum =0;

        for (int i =0; i <100; i++) {
            isNum += (i % 3==0) ? 3 : 0;
            isNum += (i % 5==0) ? 5 : 0;
            switch (isNum) {
                case 3: System.out.println("Fizz: "+ i); isNum = 0; break;
                case 5: System.out.println("Buzz: "+ i); isNum = 0; break;
                case 8: System.out.println("FizzBuzz"+ i); isNum = 0; break;
                default: System.out.println(i); isNum = 0; break;
            }
        }
    }
}
[code]

Name: Anonymous 2010-02-22 22:36

[code]class FizzBuzz {
    public static void main(String[] args){

        int isNum =0;

        for (int i =0; i <100; i++) {
            isNum += (i % 3==0) ? 3 : 0;
            isNum += (i % 5==0) ? 5 : 0;
            switch (isNum) {
                case 3: System.out.println("Fizz: "+ i); isNum = 0; break;
                case 5: System.out.println("Buzz: "+ i); isNum = 0; break;
                case 8: System.out.println("FizzBuzz"+ i); isNum = 0; break;
                default: System.out.println(i); isNum = 0; break;
            }
        }
    }
}[\code]

Name: Anonymous 2010-02-22 22:37

class FizzBuzz {
    public static void main(String[] args){

        int isNum =0;

        for (int i =0; i <100; i++) {
            isNum += (i % 3==0) ? 3 : 0;
            isNum += (i % 5==0) ? 5 : 0;
            switch (isNum) {
                case 3: System.out.println("Fizz: "+ i); isNum = 0; break;
                case 5: System.out.println("Buzz: "+ i); isNum = 0; break;
                case 8: System.out.println("FizzBuzz"+ i); isNum = 0; break;
                default: System.out.println(i); isNum = 0; break;
            }
        }
    }
}

Name: Anonymous 2010-02-23 1:11

>>202-206
...
Amid the successive failures, a note of suggestion.

isNum = 0 + (i%3==0 ? 3 : 0) + (i%5==0 ? 5 : 0);

You could also de-distribute the System.out.println(i); from all of the cases to the other side of the switch block but I'm not sure if that produces an optimization of run time along with reduction in redundancy.  It's probably not worth it.

Name: Anonymous 2010-02-23 1:30

class FizzBuzz {
    public static void main(String[] args){

        int isNum =0;

        for (int i =0; i <=100; ++i) {
        isNum = 0 + (i%3==0 ? 3 : 0) + (i%5==0 ? 5 : 0);
            switch (isNum) {
                case 3: System.out.println("Fizz: "+ i); isNum = 0; break;
                case 5: System.out.println("Buzz: "+ i); isNum = 0; break;
                case 8: System.out.println("FizzBuzz"+ i); isNum = 0; break;
                default: System.out.println(i); isNum = 0; break;
            }
        }
    }
}

Name: Anonymous 2010-02-23 1:34

#! /bin/sh

cycle='fizz $n buzz fizz $n $n fizz buzz $n fizz $n $n fizzbuzz $n $n'

echo 1
echo 2
set -- `seq 3 100`
while : ; do
  for i in $cycle ; do
    test $# -gt 0 || exit
    n=$1 ; shift
    eval echo $i
  done
done

Name: Anonymous 2010-02-23 1:35

(progn
  (format t "~{~A~^~%~}"
          (loop for i from 3 to 100
                collect (case (mod i 15)
                          ((3 6 9 12) "fizz")
                          ((5 10) "buzz")
                          (0 "fizzbuzz")
                          (t i))))
  (values))

Name: Anonymous 2010-02-23 1:37

class FizzBuzz {
    public static void main(String[] args){

        int isNum;

        for (int i =0; i <=100; ++i) {
        isNum = 0 + (i%3==0 ? 3 : 0) + (i%5==0 ? 5 : 0);
            switch (isNum) {
                case 3: System.out.println("Fizz: "+ i); break;
                case 5: System.out.println("Buzz: "+ i); break;
                case 8: System.out.println("FizzBuzz"+ i); break;
                default: System.out.println(i); break;
            }
        }
    }
}

Name: Anonymous 2010-02-23 1:38

class FizzBuzz {
    public static void main(String[] args){

        for (int i =0; i <=100; ++i) {
        int isNum = 0 + (i%3==0 ? 3 : 0) + (i%5==0 ? 5 : 0);
            switch (isNum) {
                case 3: System.out.println("Fizz: "+ i); break;
                case 5: System.out.println("Buzz: "+ i); break;
                case 8: System.out.println("FizzBuzz"+ i); break;
                default: System.out.println(i); break;
            }
        }
    }
}

Name: Anonymous 2010-02-23 1:42

--- >>208-fag   2010-02-23 07:40:53.809772132 +0100
+++ >>212-fag   2010-02-23 07:41:15.676762541 +0100
@@ -1,15 +1,13 @@
 class FizzBuzz {
     public static void main(String[] args){

-        int isNum =0;
-
         for (int i =0; i <=100; ++i) {
-        isNum = 0 + (i%3==0 ? 3 : 0) + (i%5==0 ? 5 : 0);
+        int isNum = 0 + (i%3==0 ? 3 : 0) + (i%5==0 ? 5 : 0);
             switch (isNum) {
-                case 3: System.out.println("Fizz: "+ i); isNum = 0; break;
-                case 5: System.out.println("Buzz: "+ i); isNum = 0; break;
-                case 8: System.out.println("FizzBuzz"+ i); isNum = 0; break;
-                default: System.out.println(i); isNum = 0; break;
+                case 3: System.out.println("Fizz: "+ i); break;
+                case 5: System.out.println("Buzz: "+ i); break;
+                case 8: System.out.println("FizzBuzz"+ i); break;
+                default: System.out.println(i); break;
             }
         }
     }

Name: Anonymous 2010-02-23 1:55

>>213
repeated dynamic memory allocation over single static allocation on stack.
Nice improvement, bro.

Name: Anonymous 2010-02-23 2:10

>>214
jvm does escape analysis and also no dangling pointers.

Name: Anonymous 2010-02-23 2:17

class FizzBuzz {
   public static void main(String[] args) {
      for (int i = 0, isNum = 0; i <= 100; ++i) {
         isNum = 0 + (i%3==0 ? 3 : 0) + (i%5==0 ? 5 : 0);
         switch (isNum) {
            case 3: System.out.println("Fizz: "+ i); break;
            case 5: System.out.println("Buzz: "+ i); break;
            case 8: System.out.println("FizzBuzz: "+ i); break;
            default: System.out.println(i); break;
         }
      }
   }
}

Sure is really Java in here.  Can someone program this in a language not yet used in the thread?

Name: Anonymous 2010-02-23 2:29

definitely too much coffee-fags around...

Name: Anonymous 2010-02-23 2:30

Just one more to drive the point home.
class FizzBuzz {
   public static void main(String[] args) {
      for (int i = 0; i <= 100; ++i) {
         System.out.println( (i%3==0 ? "Fizz" : "") + (i%5==0 ? "Buzz" : "") + " " + i);
      }
   }
}

Name: Anonymous 2010-02-23 2:46

>>218
for multiples of three print “Fizz” ...
>instead of the number

class FizzBuzz {
   public static void main(String[] args) {
      for (int i = 0, isNum = 0; i <= 100; ++i) {
         isNum = 0 + (i%3==0 ? 3 : 0) + (i%5==0 ? 5 : 0);
         switch (isNum) {
            case 3: System.out.println("Fizz"); break;
            case 5: System.out.println("Buzz"); break;
            case 8: System.out.println("FizzBuzz"); break;
            default: System.out.println(i); break;
         }
      }
   }
}

Name: Anonymous 2010-02-23 4:05


#lang scheme

(define (fizzbuzz x)
  (cond ((and (= 0 (modulo x 3)) (= 0 (modulo x 5))) (display "FizzBuzz"))
        ((= 0 (modulo x 3)) (display "Fizz"))
        ((= 0 (modulo x 5)) (display "Buzz"))
        (else (display x)))
  (newline)
  (if (< x 100)
      (fizzbuzz (+ x 1))
      (values)))

(fizzbuzz 1)

Name: Anonymous 2010-02-23 4:09

HAI
CAN HAS STDIO?
I HAS A VAR IZ 0
IM IN YR LOOP
    UPZ VAR!!1
    IZ VAR BIGR THAN 100?
        GTFO.
    KTHX
    IZ VAR LEFTOVAR 15 LIEK 0?
        VISIBLE "FIZZBUZZ"
    KTHX
    ORLY?
    IZ VAR LEFTOVAR 5 LIEK 0?
        VISIBLE "BUZZ"
    KTHX
    ORLY?
    IZ VAR LEFTOVAR 3 LIEK 0?
        VISIBLE "FIZZ"
    KTHX
    NOWAI
        VISIBLE VAR
    KTHX
KTHX
KTHXBYE

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