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-03 8:41 ID:KJvW0vyq

So is anyone going to attempt to solve this in constant time using a template function?

Name: Anonymous 2007-09-03 8:49 ID:KJvW0vyq

public class FizzBuzz
{
        public static void main ( String [] argv )
        {
                for( int i=0,j=0,k=0; i <= 100; i++ )
                {
                        System.out.print(i+" ");
                        if( j == 3 )
                        {       System.out.print("fizz"); j = 0; }
                        if( k == 5 )
                        {       System.out.print("buzz"); k = 0; }
                        j++;
                        k++;
                        System.out.println();
                }
        }
}

Name: Anonymous 2007-09-03 8:51 ID:KJvW0vyq

>>82
One word......

Name: Anonymous 2007-09-03 8:51 ID:Heaven

>>82
This doesn't proactively create synergies or maximize profits by following best practices. Make it more ENTERPRISE.

Name: Anonymous 2007-09-03 8:59 ID:KJvW0vyq

/**
 * Autor: Anonymous
 * Date: 2007-09-03
 * Class: FizzBuzz
 * Description: Outputs the numbers 1 to 100 on each line
 * Whilst writing fizz or buzz if the linenumber is
 * divisible by 3 or 5 respectivley.
 */
public class FizzBuzz
 {
         /* main entry point */
         public static void main ( String [] argv )
         {
                 /* For loop from 1 to 100 inclusive */
                 for( int i=0,j=0,k=0; i <= 100; i++ )
                 {
                         System.out.print(i+" ");
                         if( j == 3 )
                         {
                                 //Prints fizz when required
                                 System.out.print("fizz"); j = 0; }
                         if( k == 5 )
                         {
                                 //Prints buzz when required
                                 System.out.print("buzz"); k = 0; }
                         //Increment
                         j++;
                         k++;

                         //Print a newline character
                         System.out.println();
                 }//EndFor
         }//End main
 }//End Class: FizzBuzz

Name: Anonymous 2007-09-03 9:03 ID:9bZSHq1c

         /* main entry point -- thx joe 4 explanaton*/

Name: Anonymous 2007-09-03 9:29 ID:sIzmUEwb

10 REM ** FIZZBUSS VERSION 1.00 **
20 REM (C) HABEEBULLAH AL QADAMU SIDQ 2007
25 REM ALL RIGHT RESERVED
30 PRINT "1"
40 PRINT "2"
50 PRINT "3 BUZZ"
60 PRINT "4"
70 PRINT "5 FIZZ"
80 PRINT "6 BUZ"
90 PRINT "7"
100 PRINT "8"
110 PRINT "9 BUZZ"
120 PRINT "10 FIZZ"
130 PRINT "11"
140 PRINT "12 BUZZ"
150 PRINT "13"
160 PRINT "14"
170 PRINT "15 FIZZBUZZ"
180 PRINT "16"
190 PRINT "17"
200 PRINT "18 BUZZ"
210 PRINT "19"
220 PRINT "20 FIZZ"
230 PRINT "21 BUZZ"
240 PRINT "22"
250 PRINT "23"
260 PRINT "24 BUZZ"
270 PRINT "25 FIZZ"
280 PRINT "26"
290 PRINT "27 BUZZ"
300 PRINT "28"
310 PRINT "29"
320 PRINT "30 FIZBUZZ"
330 PRINT "31"
340 PRINT "32"
350 PRINT "33 BUZZ"
360 PRINT "34"
370 PRINT "35 FIZZ"
380 PRINT "36 BUZZ"
390 PRINT "37"
400 PRINT "38"
410 PRINT "39 BUZZ"
420 PRINT "40 FIZZ"
430 PRINT "41"
440 PRINT "42 BUZZ"
450 PRINT "43"
460 PRINT "44"
470 PRINT "45 FIZZBUZZ"
480 PRINT "46"
490 PRINT "47"
500 PRINT "48"
510 PRINT "49"
520 PRINT "50 FIZZ"
530 PRINT "51 BUZZ"
540 PRINT "52"
550 PRINT "53"
560 PRINT "54 BUZZ"
570 PRINT "55 FIZZ"
580 PRINT "56"
590 PRINT "57 BUZZ"
600 PRINT "58"
610 PRINT "59"
620 PRINT "60 FIZZBUZZ"
630 PRINT "61"
640 PRINT "62"
650 PRINT "63BUZZ"
660 PRINT "64"
670 PRINT "65 FIZZ"
680 PRINT "66 BUZZ"
690 PRINT "67"
700 PRINT "68"
710 PRINT "69 BUZZ"
720 PRINT "70 FIZZ"
730 PRINT "71"
740 PRINT "72 BUZZ"
750 PRINT "73"
760 PRINT "74"
770 PRINT "75 FIZZBUZZ"
780 PRINT "76"
790 PRINT "77"
800 PRINT "78 BUZZ"
810 PRINT "79"
820 PRINT "80 FIXX"
830 PRINT "81 BUZZ"
840 PRINT "82"
850 PRINT "83"
860 PRINT "84 BUZZ"
870 PRINT "85 FIZZ"
880 PRINT "86"
890 PRINT "87 BUZZ"
900 PRINT "88"
910 PRINT "89"
920 PRINT "90 FIZZZBUZZ"
930 PRINT "91"
940 PRINT "92"
950 PRINT "93 VUZZ"
960 PRINT "94"
970 PRINT "95 FIZZ"
980 PRINT "96 BUZZ"
990 PRINT "97"
1000 PRINT "98"
1010 PRINT "99 BUZZ"
1020 PRINT "100 FIZZ"
1030 END

Name: Anonymous 2007-09-03 10:12 ID:ytkyfT0U

>>87
Thread over.

Name: Anonymous 2007-09-03 10:20 ID:hTPXbaba

>>87
950 PRINT "93 VUZZ"

YOU HAVE FAILED.
PLEASE DIE.

Name: Anonymous 2007-09-03 10:22 ID:Heaven

>>87
NEW CHALLENGE

Write a program that produces >>87 as its output.

Name: Anonymous 2007-09-03 10:22 ID:j7NYybfP

>>87
Oh god I lol'd

Name: Anonymous 2007-09-03 10:57 ID:RbBmx4Rt

>>90

#!/bin/sh

echo '10 REM ** FIZZBUSS VERSION 1.00 **
20 REM (C) HABEEBULLAH AL QADAMU SIDQ 2007
25 REM ALL RIGHT RESERVED
30 PRINT "1"
40 PRINT "2"
50 PRINT "3 BUZZ"
60 PRINT "4"
70 PRINT "5 FIZZ"
80 PRINT "6 BUZ"
90 PRINT "7"
100 PRINT "8"
110 PRINT "9 BUZZ"
120 PRINT "10 FIZZ"
130 PRINT "11"
140 PRINT "12 BUZZ"
150 PRINT "13"
160 PRINT "14"
170 PRINT "15 FIZZBUZZ"
180 PRINT "16"
190 PRINT "17"
200 PRINT "18 BUZZ"
210 PRINT "19"
220 PRINT "20 FIZZ"
230 PRINT "21 BUZZ"
240 PRINT "22"
250 PRINT "23"
260 PRINT "24 BUZZ"
270 PRINT "25 FIZZ"
280 PRINT "26"
290 PRINT "27 BUZZ"
300 PRINT "28"
310 PRINT "29"
320 PRINT "30 FIZBUZZ"
330 PRINT "31"
340 PRINT "32"
350 PRINT "33 BUZZ"
360 PRINT "34"
370 PRINT "35 FIZZ"
380 PRINT "36 BUZZ"
390 PRINT "37"
400 PRINT "38"
410 PRINT "39 BUZZ"
420 PRINT "40 FIZZ"
430 PRINT "41"
440 PRINT "42 BUZZ"
450 PRINT "43"
460 PRINT "44"
470 PRINT "45 FIZZBUZZ"
480 PRINT "46"
490 PRINT "47"
500 PRINT "48"
510 PRINT "49"
520 PRINT "50 FIZZ"
530 PRINT "51 BUZZ"
540 PRINT "52"
550 PRINT "53"
560 PRINT "54 BUZZ"
570 PRINT "55 FIZZ"
580 PRINT "56"
590 PRINT "57 BUZZ"
600 PRINT "58"
610 PRINT "59"
620 PRINT "60 FIZZBUZZ"
630 PRINT "61"
640 PRINT "62"
650 PRINT "63BUZZ"
660 PRINT "64"
670 PRINT "65 FIZZ"
680 PRINT "66 BUZZ"
690 PRINT "67"
700 PRINT "68"
710 PRINT "69 BUZZ"
720 PRINT "70 FIZZ"
730 PRINT "71"
740 PRINT "72 BUZZ"
750 PRINT "73"
760 PRINT "74"
770 PRINT "75 FIZZBUZZ"
780 PRINT "76"
790 PRINT "77"
800 PRINT "78 BUZZ"
810 PRINT "79"
820 PRINT "80 FIXX"
830 PRINT "81 BUZZ"
840 PRINT "82"
850 PRINT "83"
860 PRINT "84 BUZZ"
870 PRINT "85 FIZZ"
880 PRINT "86"
890 PRINT "87 BUZZ"
900 PRINT "88"
910 PRINT "89"
920 PRINT "90 FIZZZBUZZ"
930 PRINT "91"
940 PRINT "92"
950 PRINT "93 VUZZ"
960 PRINT "94"
970 PRINT "95 FIZZ"
980 PRINT "96 BUZZ"
990 PRINT "97"
1000 PRINT "98"
1010 PRINT "99 BUZZ"
1020 PRINT "100 FIZZ"
1030 END'

Name: Anonymous 2007-09-03 10:59 ID:Heaven

>>90

#include <stdio.h>

int main(int argc, char *argv[])
{
    int a;
    a = 87
    printf(">>%u", a);
    puts("");
    return 0;
}

Name: Anonymous 2007-09-03 11:03 ID:KJvW0vyq

>>87
Win.

Name: Anonymous 2007-09-03 11:20 ID:DIBjhjQj

>>87
I lol'd, hard

Name: Anonymous 2007-09-03 11:28 ID:hiK4isFI

why do yall have 12 as buzz, 12 isnt divided by 5

Name: Anonymous 2007-09-03 11:44 ID:Heaven

>>96
...

Name: Seth 2007-09-03 11:50 ID:a5dRJp7w

for x in range(1, 101):
    if not x % 3:
        print str(x) + ' fizz'
    elif not x % 5:
        print str(x) + ' buzz'
    else:
        print x

Name: Anonymous 2007-09-03 12:27 ID:1C3ks67y

>>98
You fail Seth

your shit can't print fizzbuzz on %15

Name: Anonymous 2007-09-03 12:28 ID:6QeiAPbI

>>98
Which is basically what I wrote yesterday, only using more forced indentation of code.

Name: Anonymous 2007-09-03 12:31 ID:KJvW0vyq

>>96
Is this the difference between a Webmonkey and a Codemonkey?
A webmonkey is concerned with how it looks,
Whereas a codemonkey is only concerned with how it works?

Maybe the challenge was not to produce code, but to challenge the requirements.  That is what any software engineer, no any self respecting IT professional should do.

Name: Anonymous 2007-09-03 12:49 ID:+yGhcrC1

>>92
FAIL

820 PRINT "80 FIXX"
950 PRINT "93 VUZZ"
1030 END'

COMPILE ERROR MASSIVE FAIL

Name: Anonymous 2007-09-03 12:57 ID:+yGhcrC1

103 GET

Name: Anonymous 2007-09-03 13:26 ID:JxYtEFpk


(defun fizzbuzz ()
  (dotimes (i 100)
    (format t "~&~a " (1+ i))
    (when (zerop (mod (1+ i) 3)) (format t "fizz"))
    (when (zerop (mod (1+ i) 5)) (format t "buzz~%"))))

Fuck yeah format. I wonder if you could do it using only a call to format.

Name: Anonymous 2007-09-03 13:35 ID:Heaven

I love how you guys are indignantly shouting FAIL FAIL at a comically deliberate fail.

Name: Anonymous 2007-09-03 13:59 ID:Heaven

106 A$ = GET$

Name: Anonymous 2007-09-03 15:00 ID:TeEJZl9F

>>81

#include <string>
#include <sstream>
#include <iostream>

template < class T >
std::string lexical_cast( T val ) {
        std::string ret;
        std::stringstream ss;
        ss << val;
        ss >> ret;
        return ret;
}

template < int n >
struct Fizz {
        static const char* f;
};

template <int n> const char* Fizz<n>::f = "";

template <>
struct Fizz<0> {
        static const char* f;
};

template <> const char* Fizz<0>::f = " fizz";

template < int n >
struct Buzz {
        static const char* b;
};

template <int n> const char* Buzz<n>::b = "";

template <>
struct Buzz<0> {
        static const char* b;
};

template <> const char* Buzz<0>::b = " buzz";

template < int n >
struct FizzBuzz : Fizz< n % 5 >, Buzz< n % 3 >
{
        static const std::string s;
};

template <>
struct FizzBuzz<0>
{
        static const std::string s;
};

template < int n >
const std::string FizzBuzz<n>::s =
        FizzBuzz< n - 1 >::s + "\n" + lexical_cast(n) + Fizz< n % 5 >::f + Buzz< n % 3 >::b;

template <>
const std::string FizzBuzz<0>::s = "";

int main( int argc, char* argv[] ) {
        std::cout << FizzBuzz<100>::s << std::endl;
}

Name: Anonymous 2007-09-03 15:28 ID:KJvW0vyq

>>107
wouldnt compile with g++ but I take my hat off to you after realising how complex this is.

Name: Anonymous 2007-09-03 18:38 ID:Heaven

>>108
What errors did gcc give you? (and what version of gcc are you building it with?) I tested it with 3.4.6 when I wrote it, though looking back there are at least a few unnecessary parts, if not something that breaks standards.

lol templates.

Name: Anonymous 2007-09-03 19:17 ID:giicnVHy

>>109
Other fag, but:

# gcc fizzbuzz.cpp
fizzbuzz.cpp:27: error: template header not allowed in member definition of explicitly specialized class
fizzbuzz.cpp:41: error: template header not allowed in member definition of explicitly specialized class
fizzbuzz.cpp:60: error: template header not allowed in member definition of explicitly specialized class

# gcc --version
gcc (GCC) 4.2.1

Name: Anonymous 2007-09-03 19:31 ID:Heaven

>>110
Huh, that's weird. The only thing I can think of would be to remove the "template <>" from those three lines. I didn't have them there originally, but 3.4.6 bitched at me to put them in.

I should upgrade to 4.2.1 one of these days.

Name: Anonymous 2007-09-03 19:52 ID:Heaven

>>87
500 PRINT "48"
That should be a BUZZ you fucking failure piece of shit cockfaggot.

Name: Anonymous 2007-09-03 20:14 ID:Icrsx+Y0

main() { printf("1\n2\n3    fail\n4\n5    sage\n6    fail\n7\n8
\n9    fail\n10   sage\n11\n12   fail\n13\n14\n15   sagefail\n16
\n17\n18   fail\n19\n20   sage\n21   fail\n22\n23\n24   fail\n25 
 sage\n26\n27   fail\n28\n29\n30   sagefail\n31\n32\n33  
fail\n34\n35   sage\n36   fail\n37\n38\n39   fail\n40  
sage\n41\n42   fail\n43\n44\n45   sagefail\n46\n47\n48   fail
\n49\n50   sage\n51   fail\n52\n53\n54   fail\n55   sage\n56\n57 
 fail\n58\n59\n60   sagefail\n61\n62\n63   fail\n64\n65   sage
\n66   fail\n67\n68\n69   fail\n70   sage\n71\n72   fail\n73\n74
\n75   sagefail\n76\n77\n78   fail\n79\n80   sage\n81   fail\n82
\n83\n84   fail\n85   sage\n86\n87   fail\n88\n89\n90   sagefail
\n91\n92\n93   fail\n94\n95   sage\n96   fail\n97\n98\n99   fail
\n100  sage"); return 0; }


Name: Anonymous 2007-09-03 20:48 ID:KJvW0vyq

>>108 and >>81 here,

fizzbuzz.cc:26: error: template header not allowed in member definition of explicitly specialized class
fizzbuzz.cc:40: error: template header not allowed in member definition of explicitly specialized class
fizzbuzz.cc:59: error: template header not allowed in member definition of explicitly specialized class

$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.2 (Ubuntu 4.1.2-0ubuntu4)

Name: Anonymous 2007-09-03 21:14 ID:cQwMnubr

main(){int i;for(i=1;i<101;i++)printf("%d %s%s\n",i,(i%3)?"":"Fizz",(i%5)?"":"Buzz");}

Name: Anonymous 2007-09-03 21:31 ID:fCY+jKkf

You all fucking fail for printing the number when it's printing fizz and/or buzz. It's only supposed to print the number on non-fizzbuzz lines.

Name: Anonymous 2007-09-03 21:42 ID:V92FQQSh

>>116
see >>34.

Name: Anonymous 2007-09-03 21:46 ID:qYz6n4zm

>>114
Lines like

template <> const char* Fizz<0>::f = " fizz";

with the specializations can be changed to just this:

const char* Fizz<0>::f = " fizz";

Name: Anonymous 2007-09-03 22:17 ID:xJhADrtK

>>2-118 FUCK YOU ALL
………………..,-~’`¯lllllll`~,
…………..,-~*lllllllllllllllllllllllllll¯*-,
………,-~llllllllllllllllllllllllllllllllllllllllllll-,
……,-*llllllllllllllllllllllllllllllllllllllllllllllllllllll.\
….;`lllllllllllllllllllllllllll,-~~-,llllllllllllllllllll\
…..\lllllllllllllllllllllllllll/………\;;;;llllllllllll,-`~-,
…...\lllllllllllllllllllll,-*………..~-~-,…(.(¯*,`,
…….\llllllllllll,-~…………………)_-\..`*;..)
……..\,-*¯,*)…………,-~*`~.………….../
……...|/.../…/~,…...-~,-~`;……………./.\
……../.../…/…/..,-,..~,.`~……………....\
…….|.../…/…/.*...\...……………………)….)¯~,
…….|./…/…./…….)……,.)*~-,……….../….|..)…~-,
……/./.../…,*-,…..-,…*….,---…...\…./…../..|……...¯``*~-
…...(……….)*~-,….`.,-~.,-*……|…/.…/…/…………\
…….*-,…….*-,...~,..``.,,,-……….|.,...,*…|…...\
……….*,………-,…)-,…………..,-*...,-*….(`-,…………\
..............f-,………-,/…-,___,,-~….,-*……|…`-,..

Name: Anonymous 2007-09-03 22:18 ID:JxYtEFpk

>>116
see >>1

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