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

90% of /prog/ can't write FizzBuzz

Name: The antagonist 2008-04-25 12:38

Prove me wrong

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

Name: Anonymous 2008-04-27 16:59

>>119,120
This is actually and enjoyable thread. You guys are too grumpy.

Name: Anonymous 2008-04-27 16:59

>>120
It's incredible how much fail can accumulate in just one *chan

Name: Anonymous 2008-04-27 17:06

God-damn, I thought a ``post" variant was made long time ago.

Name: Anonymous 2008-04-27 19:14

>>118
It's not so much an encouraged Python practice as something people carry over from Perl.

>>121
Not really. Everything in the thread is either trivial or lifted from somewhere else.

Name: Anonymous 2008-04-27 23:28

>>124
I didn't say it is instructive, I said it is enjoyable. Also, what do you care if posts were lifted from somewhere else? Everyone is anonymous anyway, it doesn't matter.

Name: Anonymous 2008-04-28 1:44

mrvacbob on /prog/

<@MrVacBob> i should add reporting i guess
<@MrVacBob> dis moderators are.... some people, i guess, but i'm the only one who would read prog and i don't understand it at all

Name: Anonymous 2008-04-28 5:05

<?php

/***********************\
| FizzBuzz Generator    |
| @version 0.0.1 alpha    |
| @creator Anonymous    |
\***********************/

interface IFizzBuzz
{
    public function setFizzBuzz($fizz = null, $buzz = null);
    public function checkFizz($int);
    public function checkBuzz($int);
    public function generateFizzBuzz();
}

class FizzBuzz implements IFizzBuzz
{
    /**
     * Fizz
     *
     * @var string
     */
    public $fizzText = 'Fizz';
    /**
     * Buzz
     *
     * @var string
     */
    public $buzzText = 'Buzz';
    /**
     * Lower interger range.
     *
     * @var int
     */
    public $lowerInt = 1;
    /**
     * Upper interger range.
     *
     * @var int
     */
    public $upperInt = 100;
   
    /**
     * Constructor.
     *
     * @param string $fizz    Fizz text.
     * @param string $buzz    Buzz text.
     * @return void
     */
    public function setFizzBuzz($fizz = null, $buzz = null)
    {
        if(isset($fizz)) $this->fizzText = $fizz;
        if(isset($buzz)) $this->buzzText = $buzz;
    }
   
    /**
     * Checks number for Fizz.
     *
     * @param int $int    Possibly Fizz.
     */
    public function checkFizz($int)
    {
        return ($int % 3 == 0) ? true : false;
    }
   
    /**
     * Checks number for Buzz.
     *
     * @param int $int    Possibly Buzz.
     */
    public function checkBuzz($int)
    {
        return ($int % 5 == 0) ? true : false;
    }
   
    /**
     * Iterates through FizzBuzz intergers.
     *
     * @return array    FizzBuzz test result.
     */
    public function generateFizzBuzz()
    {
        $result = array();
        for($i = $this->lowerInt; $i <= $this->upperInt; $i++)
        {
            $boolFizz = $this->checkFizz($i);
            $boolBuzz = $this->checkBuzz($i);
           
            $fbRow = '';
            if($boolFizz) $fbRow .= $this->fizzText;
            if($boolBuzz) $fbRow .= $this->buzzText;
            if(!$boolFizz && !$boolBuzz) $fbRow .= $i;
            $result[] = $fbRow;
        }
       
        return $result;
    }
}

interface IFormatter
{
    public function newline($str);
}

class FizzBuzzFormatter implements IFormatter
{
    /*
     * Converts FizzBuzz row to newline string.
     *
     * @param string $str    FizzBuzz result row.
     * @return string        FizzBuzz formatted result row.
     */
    public function newline($str)
    {
        return "<div>$str</div>";
    }
}

$fizzbuzz = new FizzBuzz;
$fbArray = $fizzbuzz->generateFizzBuzz();

$fbFormatter = new FizzBuzzFormatter;

foreach($fbArray as $fb)
{
    print $fbFormatter->newline($fb);
}

Name: Anonymous 2008-04-28 5:17

        return ($int % 3 == 0) ? true : false;
i would like you to write a formal explanation of the ternary operator and tell me why that statement is so redundant

Name: Anonymous 2008-04-28 6:21

>>128
too lazy, otherwise i would have added more garbage to my code

i'm not really sure why i added the ternary operator in there

but you can keep it as a momento of my shitty code

Name: Anonymous 2008-04-28 7:53

>>129
Uno momento?

Name: Anonymous 2008-04-28 14:04

>>128
redundant is in the eyes of the compiler

Name: Anonymous 2008-04-28 14:21

>>131
Very true.

Name: Anonymous 2008-04-28 14:22

>>131
That made little to none sense.

Name: Anonymous 2008-04-28 14:23

Uhm, little or none.

Name: Anonymous 2008-04-28 14:47

To person posting php code all over the board: stop it. STOP IT. Learn perl. You will be more happy this way. And so will I.

Name: Anonymous 2008-04-28 14:51

90% of the people here read to many blags and have already heard about the fizzbuzz shite months ago

GTFO
GO KILL YOURSELF

Name: Anonymous 2008-04-28 18:17

>>129
hint: It returns true or false, based on a conditional statement

Name: Anonymous 2008-04-28 18:21

>>136
blags
go back to /xkcd/ please

Name: Anonymous 2008-04-29 9:58

// Fizz Buzz

#include <iostream>
using namespace std;

int nums[101];

int main ()
{

for (int i = 1; i < 101; i ++)
{

if ( (i % 3) == 0)
    cout << "Fizz \n";

else if ( (i % 5) == 0)
    cout << "Buzz \n";

else if ( ((i % 3) == 0) && ((i % 5) == 0))
    cout << "FizzBuzz \n";

else
    cout << i << "\n";

}

return 0;

}

Name: Anonymous 2008-04-29 10:00

>>139

So i herd u liek mudkipz?

Name: Anonymous 2008-04-29 10:01

>>139

Actually, I think you believed to be writing in C-Code.  That is C# syntax, and will print out Buzz Fizz.

LOL @ feeble attempt.

Go back to your shithole

Name: Anonymous 2008-04-29 10:03

>>141

TROLL

Name: Anonymous 2008-04-29 10:03

>>142

DICK BUTT

Name: 139 2008-04-29 10:03

>>139

HA HA DISREGARD THAT I SUCK COCKS

Name: Anonymous 2008-04-29 10:40

You're not using enough design patterns! In PHP! http://www.fluffycat.com/PHP-Design-Patterns/

Name: Anonymous 2008-04-29 11:11

>>145
Click photo to enlarge
http://www.fluffycat.com/photograph--1/
Fatal error: Call to undefined function: numberofphotosfortopicname() in /home/fluff4/public_html/core/photo_functions.php on line 176

I lold.

Name: Anonymous 2008-04-29 13:47

// C
include <stdio.h>
int main() {
printf("lol");
return 69;
}

Name: Anonymous 2008-04-29 14:04

return 69;
wuts it do?

Name: Anonymous 2008-04-29 16:49


import Control.Monad.Instances
import Function
import Monad

fizzBuzz =
   map snd $ zipWith (flip ($)) (map ((,) [] . show) [1..100]) $
      (zipWith (.) `on` uncurry ((.) (cycle . reverse) . flip (:) . flip replicate id . subtract 1))
         (3, (,) [] . ("Fizz" ++) . fst) (5, const $ join (,) "Buzz")

main = mapM_ putStrLn fizzBuzz

Name: Anonymous 2008-04-29 17:07

>>149
Hello I am >>6 and you have been trolled and outsourced.

Name: Anonymous 2008-04-29 17:07

oh fuck wait I have been trolled

Name: Anonymous 2008-04-29 18:09

lol scalable

import Control.Monad.Instances
import Control.Arrow
import Monad

fizzBuzz =
   map snd $ zipWith (flip ($)) (map ((,) [] . show) [1..100]) $ foldl1 (zipWith $ flip (.))
           $ map (uncurry ((.) (cycle . reverse) . flip (:) . flip replicate id . subtract 1))
           $ liftM2 (:) ((second $ const . join (,)) . head) (map (second $ (.) (join (,)) . (. fst) . flip (++)) . tail)
           $ [(3, "Fizz"), (5, "Buzz")]

main = mapM_ putStrLn fizzBuzz

Name: Anonymous 2008-04-29 18:33


print"\n".join(map(lambda x:str([x,"Fizz","Buzz","FizzBuzz"][(x%3==0)+(x%5==0)*2]),range(1,101)))

Name: Anonymous 2008-04-29 20:07

>>153
Functional programming considered harmful
       Guido Van rossum

Name: Anonymous 2008-04-29 21:24

Bow down before the ENTERPRISE
package fizzbuzz;

public interface IFizzBuzz {
   public void setStart();
   public void setEnd();
   public String getFizzBuzz();
}
=================================================
package fizzbuzz;

/**
 * Singleton adapter factory
 */
public class FizzBuzzFactory {
    public static final FizzBuzzFactory INSTANCE = new FizzBuzzFactory();

    private FizzBuzzFactory() {
        registerAdapters();
    }

    public <T> createInstance(Class<T> clazz) {
        if (clazz == IFizzBuzz.class) {
        return new FizzBuzzImpl();
        } else return null;
    }

}
=================================================
package fizzbuzz.internal;

public class FizzBuzzImpl implements IFizzBuzz {
    private int fStart;
    private int fEnd;

    /*package*/ FizzBuzzImpl() {}

    public void setStart(int start) {
        fStart = start;
    }

    public void setEnd(int end) {
        fEnd = start;
    }

    private boolean getFizz(int i) {
        return i % 3 == 0;
    }

    private boolean getBuzz(int i) {
        return i % 5 == 0;
    }

    public String getFizzBuzz() {
        String result = "";
    for (int i = fStart; i <= fEnd; i++) {
            if (getFizz(i) && getBuzz(i))
                result += "FizzBuzz";
            else if (getFizz(i))
                result += "Fizz";
            else if (getBuzz(i))
                result += "Buzz";
            else result += i;
        }
        return result;
    }
}
=================================================
import junit.framework.*;

public class TestFizzBuzz extends TestCase {
    public void setUp() {
    }
    public void tearDown() {
    }
    public void testGetFizzBuzz() {
        IFizzBuzz f = FizzBuzzFactory.INSTANCE.createInstance(IFizzBuzz.class);
        f.setStart(1);   
        f.setEnd(100);
        AssertEquals(f.getFizzBuzz(),

"123Fizz45Buzz6Fizz789Fizz10Buzz1112Fizz131415FizzBuzz161718Fizz1920Buzz21Fizz222324Fizz25Buzz2627F

izz282930FizzBuzz313233Fizz3435Buzz36Fizz373839Fizz40Buzz4142Fizz434445FizzBuzz464748Fizz4950Buzz51

Fizz525354Fizz55Buzz5657Fizz585960FizzBuzz616263Fizz6465Buzz66Fizz676869Fizz70Buzz7172Fizz737475Fiz

zBuzz767778Fizz7980Buzz81Fizz828384Fizz85Buzz8687Fizz888990FizzBuzz919293Fizz9495Buzz96Fizz979899Fi

zz100Buzz";
    }   
}

Name: Anonymous 2008-04-29 21:54

>>154
Guido once gave me bad advice on how to do a simple task in Python. He can suck moot's cock for all I care.

Name: Anonymous 2008-04-29 22:05

EXPERT PROGRAMMER

Name: Anonymous 2008-04-29 22:16

>>155
I admire your dedication, good sir. Satire like that I greatly apreciate. Greatly indeed.

Name: Anonymous 2008-04-29 22:20

>>154
Surely you jest.

Name: Anonymous 2008-04-30 21:22

>>127,155
I can't tell which one is java and which one is php now

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