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

I Propose a challenge. (FIZZ BUZZ)

Name: Anonymous 2007-09-01 20:19 ID:Ei0Nz+V2

The fizz buzz challenge

Make a program(in the language of your choice), that goes like this:

1)Prints all numbers from one to one hundred
2)For every number that can be divided with 3, it writes "fizz" next to the number.
3)For every number that can be divided with 5, it writes "buzz".

Should look like this:

1
2
3 Buzz
4
5 Fizz
6 Buzz
7
8
9 Buzz
10 Fizz
11
12 Buzz
13
14
15 FizzBuzz
16
17
18 Buzz

This a common problem employers give to seperate the Expert programers from the Enterprise Qulity Programmers. Surprisingly, not many programmers can. I made one in BASIC in 5 minutes.

Lets see how /PROG/ stands up to this.

Name: Anonymous 2007-09-01 20:24 ID:Heaven

This was a common topic among bunny-brained Web 2.0 circlejerkers this spring.
Fix'd.

Name: Anonymous 2007-09-01 20:26 ID:Heaven

yawn, gtfo fag

Name: Anonymous 2007-09-01 20:26 ID:XNxtzNfJ


(define (buzz x)
  (if (= 1 x) (display 1)
      ((display x)
      (if (= (remainder x 3) 0) (display " fizz") (display " "))
      (if (= (remainder x 5) 0) (display " buzz") (display " "))
      (newline)
      (buzz (- x 1)))))

(buzz 100)


Not tested, but should be good. Written in 7 minutes.

Name: Anonymous 2007-09-01 20:34 ID:qPfamYiZ

####
# This is according to the problem set, but the example
# had the words "Fizz" and "Buzz" switched.
# Less than 3 minutes.
def fizzbuzz():
    for num in range(1, 101):
        word = " "
        if not num % 3:
            word += "Fizz"
        if not num % 5:
            word += "Buzz"
       
        print "%d%s" % (num, word)

if __name__ == "__main__":
    fizzbuzz()

Name: Anonymous 2007-09-01 20:35 ID:Heaven

sage sage buzz sage sage sage sage sage sage fizz

Name: Anonymous 2007-09-01 20:36 ID:Ei0Nz+V2

meh. might as well post mine in basic.

for i=1 to 100
if i mod 3=0 then buzz$="Buzz"
if i mod 5=0 then fizz$="Fizz"
print i;" ";fizz$;buzz$
buzz$=""
fizz$=""
next

SEVEN LINES BITCH!

Name: Anonymous 2007-09-01 20:40 ID:Heaven

FUCK YOU LOT


DONT START THiS THREAD

Name: Anonymous 2007-09-01 20:44 ID:qPfamYiZ

Is this about line count now? >:]

exec('for num in range(1, 101):\n\tword=" "\n\tif not num % 3: word += "Fizz"\n\tif not num % 5: word += "Buzz"\n\tprint "%d%s" % (num, word)\n')

One liner? :3

Name: Anonymous 2007-09-01 20:50 ID:Ei0Nz+V2

>>8 DONT START THiS THREAD

Bit to late for that.

Name: sage 2007-09-01 20:53 ID:Heaven

1
2
3    fail
4
5    sage
6    fail
7
8
9    fail
10   sage
11
12   fail
13
14
15   sagefail
16
17
18   fail
19
20   sage
21   fail
22
23
24   fail
25   sage
26
27   fail
28
29
30   sagefail
31
32
33   fail
34
35   sage
36   fail
37
38
39   fail
40   sage
41
42   fail
43
44
45   sagefail
46
47
48   fail
49
50   sage
51   fail
52
53
54   fail
55   sage
56
57   fail
58
59
60   sagefail
61
62
63   fail
64
65   sage
66   fail
67
68
69   fail
70   sage
71
72   fail
73
74
75   sagefail
76
77
78   fail
79
80   sage
81   fail
82
83
84   fail
85   sage
86
87   fail
88
89
90   sagefail
91
92
93   fail
94
95   sage
96   fail
97
98
99   fail
100  sage

Name: Anonymous 2007-09-01 20:57 ID:lv6u7ff4

NOTE: The following code was written entirely in the reply box, so it's untested.


#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
    for (int i=1; i<=100; ++i)
    {
        cout << i;
        if (!(i%3)) cout << " Fizz";
        if (!(i%5)) cout << " Buzz";
        cout << endl;
    }

    return 0;
}

Name: Anonymous 2007-09-01 21:04 ID:zxVKaHgf

Forth. <5 minutes. This is a lousy challenge--I think something like a Huffman encoder would be much better.

Indentation is for readability only. I could have written the whole thing on one line.

: buzz
    1 DO
    I DUP .
    DUP 3 MOD 0= IF
        ."  fizz"
    THEN
    5 MOD 0= IF
        ."  buzz"
    THEN
    CR
    LOOP ;

100 buzz

Name: Anonymous 2007-09-01 21:08 ID:Ei0Nz+V2

>>12
works. I tested it

Name: Anonymous 2007-09-01 21:17 ID:KG6Ersun

the "real" fizz buzz isn't supposed to print the number if it's printing fizz and/or buzz.

Name: Anonymous 2007-09-01 21:22 ID:Ei0Nz+V2

I dont giva crap.

Name: Anonymous 2007-09-01 21:37 ID:4/WvFAYb

DIVISION IS FUCKING SLOW
public class FizzBuzz {
    public static void main(String[] args) {
        for(int i=1,t=1,f=1; i<=100; i++,t++,f++) {
            System.out.print(i+" ");
            if(t==3) { System.out.print("fizz"); t=0; }
            if(f==5) { System.out.print("buzz"); f=0; }
            System.out.println();
        }
    }
}

Name: Anonymous 2007-09-01 21:43 ID:zxVKaHgf

>>17
[hidden]JAVA IS FUCKING SLOW[/hidden]
Fixed.

Name: Anonymous 2007-09-01 22:12 ID:Heaven

>>18
Fail

Name: Anonymous 2007-09-01 22:33 ID:ebsLT/vu

>>18
BAWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

Name: Anonymous 2007-09-01 22:43 ID:HCyO6GN+

#include <iostream>

using namespace std;

int main ()
{
    for (int i = 1; i < 101; i++)
    {
        cout << i << " ";
        if (i %3 == 0)
            cout << "Fizz";
        if (i%5 == 0)
            cout << "Bizz";
        cout << endl;
    }
    return 1;
}

Name: Anonymous 2007-09-01 22:52 ID:lv6u7ff4

>>21
see >>12

Name: Anonymous 2007-09-02 0:00 ID:FAq2f+pY

>>21
STOLEN

Name: Anonymous 2007-09-02 0:15 ID:C7JSffbb

<?php
for ($i=1; $i <= 100; $i++){
    if ($i%3 == 0){
        echo "$i Fizz<br />";
    }elseif($i%5 == 0){
        echo "$i Buzz<br />";
    }else{
        echo "$i <br />";
    }
}
?>

Name: Anonymous 2007-09-02 0:16 ID:yOdw3RJc

[pre]let f x = (if x `mod` 3 == 0 then "Fizz" else []) ++ (if x `mod` 5 == 0 then "Buzz" else []) in mapM_ (\x -> putStrLn (show x ++ " " ++ f x)) [1 .. 100][/pre]

Name: Anonymous 2007-09-02 0:17 ID:FAq2f+pY

It seems /prog/ is doing fairly well... Another challenge will come soon...

Name: Anonymous 2007-09-02 0:25 ID:Heaven

>>26
as soon as your professor assigns you more homework, right?

Name: Anonymous 2007-09-02 0:40 ID:zGTdA0Fh

>>27
as soon as your teacher assigns you more homework, right?

Fixed that for you, bucko.

Name: Anonymous 2007-09-02 1:17 ID:Heaven

>>28
>as soon as your pre-school teacher assigns you more homework, right?
Fixed futher

Name: Anonymous 2007-09-02 1:23 ID:+jmilrhX

>>29
as soon as your [b]nursery-school teacher[/b] assigns you more homework, right?

Name: Anonymous 2007-09-02 2:08 ID:Heaven

>>30
You're just bitter because you're a BBCode 101 dropout.

Name: Anonymous 2007-09-02 4:55 ID:+S0DwrAh

HAY I REED JOEL ON SOFTWAER I AM EXPERT PGROAGAMAR AI M AIR!!11111111

Name: Anonymous 2007-09-02 5:26 ID:yXa5pFup

>>24
Missed out the fizzbuzz requirement, fuck wit. Also, fails for "<br/>"


<?php
for($i=0;$i<101;$i++){echo$i." ";if($i%3==0){echo"Fizz";}if($i%5==0){echo"Buzz";}echo"\n";}
?>

Name: Anonymous 2007-09-02 6:21 ID:soxI90AR

perl:
print+Fizz x!($_%3)./0|5$/||Buzz||$_,$/for 1..100

factor:
100 [ 1+ dup 15 mod zero? [ drop "FizzBuzz" ] [ dup 3 mod zero? [ drop "Fizz" ] [ dup 5 mod zero? [ drop "Buzz" ] [ number>string ] if ] if ] if print ] each

Name: Anonymous 2007-09-02 7:46 ID:2Kos+EeY

print '\n'.join((lambda o=('','Fail')[not n%3]+('','Sage')[not n%5]:(o,`n`)[not o])()for n in xrange(1,101))
Untested, but should work.

Name: Anonymous 2007-09-02 7:50 ID:TNwnL0cy

so this is like 4chan but with cranky programmers instead of pictures huh

Name: Anonymous 2007-09-02 8:01 ID:yXa5pFup

>>36
so this is like 4chan
Look at your address bar, cockfuck, this is 4chan.

go back to /v/ and/or /b/ retard.

Name: Anonymous 2007-09-02 8:14 ID:O4oc/Lt0

<?php
for($i=1;$i<101;$i++)echo $i.($i%3?'':'Fizz').($i%5?'':'Buzz')."\n";
?>


upgraded version

Name: Anonymous 2007-09-02 8:42 ID:VPOgLPe0

GML:
var _String, _i;
_String = "";
for (_i = 0; _i<101; _i+=1) {
    _String = _String+string(i)+" ";
    if ((_i mod 5)==0) _String = _String + "Fizz";
    if ((_i mod 3)==0) _String = _String + "Buzz";
    _String = _String+"#";
}

draw_text(x, y, _String);

Name: Anonymous 2007-09-02 8:43 ID:VPOgLPe0

Ew, sorry:

for (_i = 1; _i<101; _i+=1) {

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