Fizz buzz fizzbuzz

Dafuq is the Fizz buzz at?

void fizzbuzz() {
int i = 0;
for(;;) {
i++;
System.out.println(i%5==0?i%3==0?"fizzbuzz":"buzz":i%3==0?"fizz":i);
}
}

Other urls found in this thread:

github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition
css-tricks.com/tales-of-a-non-unicorn-a-story-about-the-trouble-with-job-titles-and-descriptions/
twitter.com/NSFWRedditVideo

what shitty language is that?

that's a delicious spaghetti you've got there

Literally ambiguous

r8
def foo1():
return print("\n".join(map(lambda i: "fizzbuzz"[i*i%3*4:8--i**4%5] or str(i),range(1,101))))

Something University's love to teach in

why is that a function? can't you just print and be done with it?

So you can print it whenever you want???

You wish you could make spaghetti that delicious

I'm only somewhat embarrassed by this
#include
#include


struct fizzbuzz {
int i;
void(*run)(struct fizzbuzz *self);
};
void check_three(struct fizzbuzz *self);
void check_five(struct fizzbuzz *self);

int get_single_char(void)
{
int i = 0;
unsigned char c, prev;
while ((c = getchar()) != '\n') {
prev = c;
++i;
}
if (i > 1) {
return EOF;
}
return prev;
}

void check_three(struct fizzbuzz *self)
{
char c;
printf("Is %d divisible by 3? ", self->i);
c = get_single_char();
if (c == EOF) {
goto err;
}
switch (c) {
case 'Y':
case 'y':
puts("Fizz");
self->run = check_five;
break;
case 'N':
case 'n':
self->run = check_five;
break;
default:
goto err;
}
return;

err:
puts("Invalid input.");
}

void check_five(struct fizzbuzz *self)
{
char c;
printf("Is %d divisible by 5? ", self->i);
c = get_single_char();
if (c == EOF) {
goto err;
}
switch (c) {
case 'Y':
case 'y':
puts("Buzz");
self->run = check_three;
++self->i;
break;
case 'N':
case 'n':
self->run = check_three;
++self->i;
break;
default:
goto err;
}
return;

err:
puts("Invalid input.");
}

struct fizzbuzz *fizzbuzz_new(void)
{
struct fizzbuzz *fb = malloc(sizeof(*fb));
fb->i = 0;
fb->run = check_three;
return fb;
}

int main(void)
{
struct fizzbuzz *fb;
fb = fizzbuzz_new();
while (1) {
fb->run(fb);
}
return 0;
}

What the fuck?

(define (fizzbuzz n) (
(begin
(define (helper n current) (
(cond ((= (module n 3) 0)
(display "fizz"))
((= (module current 5) 0)
(display "buzz"))
((and (= (module current 3) 0) (= (module current 5) 0)
(display "fizzbuzz"))
(else (display current))))
(display "\n")
(if (< current n)
(helper n (+ current 1))
(display))))
(helper n 1))))
; fuck this

>What the fuck?
That's the usual reaction when most people see my code

I guess most people have never seen perfection before

This is fucking hilarious

Please stop with putting all functionality in to one line. How am I supposed to read this if I was your coworker?

inspired by you but why do you return the print function? That just returns none.

map(lambda x:((x, 'fizz'),('buzz','fizzbuzz'))[not x % 3][not x % 5], range(100))

for i in xrange(1,51):
msg = ''
if i % 3 == 0:
msg += 'Fizz'
if i % 5 == 0:
msg += 'Buzz'
print msg or i

for i in range(1,101):
print("FizzBuzz"[i*i%3*4:8--i**4%5] or i)

Is this fine?
#include

int main()
{
int count = 1;
while (count < 101) {
if (count % 5 == 0 && count % 3 == 0) {
printf("fizzbuzz\n");
} else if (count % 5 == 0) {
printf("fizz\n");
} else if (count % 3 == 0) {
printf("buzz\n");
} else {
printf ("%d\n", count);
}
count++;
}
}

You don't need brackets for only one instruction.

Enjoy your upcoming bug tickets.

>Enjoy your upcoming bug tickets.
if (count % 5 == 0 && count % 3 == 0)
puts("Fizzbuzz");


You are an idiot if that causes a bug. Fucking newfag learn C.

css = best lang body{counter-reset: item}
div{counter-increment: item}
div:not(:nth-of-type(5n)):before{content: counter(item) ""}
div:nth-of-type(3n):before{content: "Fizz"}
div:nth-of-type(5n):after{content: "Buzz"}

Enjoy being unemployed.

You'll love tracking a bug when you or a coworker will add an instruction to the condition without adding the braces.

Shit happens, learn to prevent it.

>pretending to be an employed programmer on Sup Forums
>implying someone will add code to an exercise

Wewlad

Also

>having illiterate code monkeys as coworkers

Sucks to be you

FizzBuzz is an interview question. If I were interviewing you, I will check both your coding style and your ability to solve the "problem".

You must be a numale. What was highlighted is a C best practice. There is way more elegance in Than . Also, >using printf when there is no format string

You know the compiler will translate it to a puts function. Please, kill yourself.

I did my first FizzBuzz the other day after doing a Eulers Project. I'm working my way through the Sup Forums programming challenges.

fuck my formatting sucks dick

#include
#include

int main()
{
for(int i = 1; i

var fb = []
for (var i = 0; i < 101; i++) {
fb.push(i)
}
for (var i = 0; i < 101; i+=3)
{
fb[i] = 'Fizz'
}
for (var i = 0; i < 101; i+=5)
{
fb[i] = 'Buzz'
}
for (var i = 0; i < 101; i+=15)
{
fb[i] = 'FizzBuzz'
}
console.log(fb.join('\\n'))

Is the third conditional really necessary? You could just use print instead of println and add a /n print at the end.

Disregard, I had a brain fart

Do you not know what a ternary operator is? I'll clean it up for you babby

(i%5==0?(i%3==0?"fizzbuzz":"buzz"):(i%3==0?"fizz":i))

Does 5 divide into it? If yes... Does 3 divide into it? If yes again, fizzbuzz, if no, then 5 divides into it, so buzz.
If 5 doesn't divide into it... Well, does 3? If yes, then fizz. If not, print i.

I didn't use parenthesis because you should be able to figure it out for yourself

#lang racket

(define (fizzbuzz n)
(match* ((modulo n 3) (modulo n 5))
[(0 0) "FizzBuzz"]
[(0 _) "Fizz"]
[(_ 0) "Buzz"]
[(_ _) (number->string n)]))

(module+ main
(for ([n (in-range 1 101)])
(displayln (fizzbuzz n))))

> a C best practice
Source ?

> way more elegance
Right, but still more error prone.

> the compiler will translate it to a puts function
I've not written that snippet m8.

shit nigger what are you doing?

defmodule FizzBuzz do
def run(n) do
1..n
|> Enum.map(fn(n) ->
case {rem(n, 3), rem(n, 5)} do
{0, 0} -> "FizzBuzz"
{0, _} -> "Fizz"
{_, 0} -> "Buzz"
{_, _} -> n
end
end)
|> Enum.each(&IO.puts/1)
end
end

Is this any better? I have never done any C before, that's why the original was so shitty
#include

int main()
{
int count = 1;
while (count < 10001) {
if (count % 5 == 0 && count % 3 == 0)
puts("fizzbuzz");
else if (count % 5 == 0)
puts("fizz");
else if (count % 3 == 0)
puts("buzz");
else
printf("%d\n", count);
count++;
}
}

This one probably isn't any better. I ran my original compared to the new one and it's faster while using less CPU

You can omit the first test if you butt fuddle the rest of your code.

static bool PrintIfDivisible(int i, int mod, string str)
{
if (i % mod != 0)
return false;
Console.Write(str);
return true;
}

static void Main(string[] args)
{
for (int i = 1; i

we know what your shit code does, it doesnt justify your formatting

>babby

U mad u can't write one huh

if (val % 3 == 0 && val % 5 == 0) return "FizzBuzz"
if (val % 3 == 0) return "Fizz"
if (val% 5 == 0) return "Buzz"
return toString(val)

#include
#include

#define FIZZBUZZ_CASE(term) case term: printf("FizzBuzz"); break
#define FIZZ_CASE(term) case term: printf("Fizz"); break
#define BUZZ_CASE(term) case term: printf("Buzz"); break
#define EMPTY_CASE(term) case term:
#define NORMAL_CASE(term) case term: printf("%d", i); break

int main(void)
{
int i;
for (i = 1; i = 0) j = j - 15;

switch (j)
{
FIZZBUZZ_CASE(0);
EMPTY_CASE(1);
NORMAL_CASE(2);
FIZZ_CASE(3);
NORMAL_CASE(4);
BUZZ_CASE(5);
FIZZ_CASE(6);
EMPTY_CASE(7);
NORMAL_CASE(8);
FIZZ_CASE(9);
BUZZ_CASE(10);
NORMAL_CASE(11);
FIZZ_CASE(12);
EMPTY_CASE(13);
NORMAL_CASE(14);
}
printf("\n");
}

return 0;
}

Enjoy your heartbleed, fag.

How'd i do Sup Forums, did i get the job?

for i in range(0,101):

fizz = i % 3 == 0;
buzz = i % 5 == 0;

if fizz & buzz:
print ('Fizzbuzz')
elif fizz:
print ('Fizz')
elif buzz:
print ('Buzz')
else:
print (str(i))

npm install fizzbuzz

var fizzbuzz = require('fizzbuzz');
fizzbuzz(1, 100);

if number is divisible by 3 and 5 print fizzbuzz
else if the number is divisible by 3 print fizz
else if the number is divisible by 5 print buzz
else print number
did I do good

github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

whatisfizzbuzz.jpg

Here, faggot

void fizzbuzz() {
for(int i = 1;;i++) {
String s = i%3==0?"fizz":"";
s += i%5==0?"buzz":"";
System.out.println(s.isEmpty()?i:s);
}
}

No more tears?

nice b8 m8

This is the best argument against Java'scommunity I've ever seen

#include

void increment ( char* no )
{
if (*no == '9') {
*no = '0';
increment(no-1);
} else {
(*no)++;
}
}

char* seek ( char* no )
{
for (;*no == '0';++no);
return no;
}

int divisible_by_3 ( char* no )
{
char s[] = "00000000";

for (int k = 0; k < 7; ++k) {
if (no[k] == '0') continue;

for (int i = 0; i < 8;++i)
for (int j = no[i]-'0'; j>0; --j)
increment(s+7);

return divisible_by_3(s);
}

switch (no[7]) {
case '0':
case '3':
case '6':
case '9':
return 1;
default:
return 0;
}
}

int divisible_by_5 ( char* no )
{
switch (no[7]) {
case '0':
case '5':
return 1;
default:
return 0;
}
}

int main (void)
{
for(char s[] = "00000001"; s[5]=='0'; increment(s+7)) {
if (divisible_by_3(s)) {
if (divisible_by_5(s)) {
puts("FizzBuzz");
} else {
puts("Fizz");
}
} else if (divisible_by_5(s)) {
puts("Buzz");
} else {
puts(seek(s));
}
}
}

>tfw engineer

function [] = fizzbuzz_f()
a = 1;
while 1
if mod(a,5) == 0 && mod(a,3) == 0
disp('FizzBuzz');
pause(.5);
a = a+1;
continue
end
if mod(a,5) == 0
disp('Buzz');
pause(.5);
a = a+1;
continue
end
if mod(a,3) == 0
disp('Fizz');
pause(.5);
a = a+1;
continue
else
disp(a);
a = a+1;
pause(.5);
end
end
end

This is what happens when you let business majors near a keyboard.

Lisp quality
(define (fizzbuzz n)
(define (modtest x y) (= (modulo x y) 0))
(map (lambda (x)
(cond ((modtest x 15) 'fizzbuzz)
((modtest x 3) 'fizz)
((modtest x 5) 'buzz)
(else x)))
(iota n 1)))

Noobs

Loltier

what the fuck nigger

also, sweet digits

>

Ahahahahaha..

Also checked that S W E E T quads

Are you ready for my final form?

def _ __
0 . upto __ do
|__ |__
p yield __|
__
end end
_=->_ do
"FizzBuzz"[
_ *
_ %3 *
4 ...
8 >>
_ **
4%5 ][
/.+/ ]||
_ end
_ 100 do
|__ |__
_.
call __
end

What the hell?

loli

def fizzbuzz():
n = 101
for i in range(n):
print("if" + str(i) "% 15 == 0:")
print(' print('fizzBuzz')')
print('if' + str(i) +' % 5 == 0:')
print(' print('buzz')')
print('if' + str(i) + "% 3 == 0:")
print(' print('fizz')")

for i in range(100):
message = "fizz" if i % 3 == 0 else i
message = "buzz" if i % 5 == 0 else message
print(message)

Loli stop hiding :3

>module

kek good stuff user, I'll use this library one day, some suggestions:
>change the printf("is %d divisible?") stuff to call a funcptr, so apps using your fizzbuzz library can provide their own input function (use the current printf code as the default ofc)
>make outputting fizz/buzz call a funcptr instead also, using an enum for the outputted value
>fizzbuzz_destroy, using pointer arithmetic and memset to ensure the struct is securely deleted
>convert it to C++, make outputs return a FizzBuzzOutput class which has FizzOutput and BuzzOutput as child classes, etc you get the point

>using match
That's just cheating

I did this 2 days ago while I was bored from my stupid Rails project..

I tried to obfuscate it as much as possible, here is a "clearer" version:

def _(__)
0.upto(__) do |__|
__
p yield __ |__
end
end

_=->_ do
"FizzBuzz"[_*_%3*4...8>>_**4%5][/.+/]||_
end

_ 100 do |__|
__
_.call __
end


Basically it's based on the "FizzBuzz of the christ", but it has a lot of fancy stuff, i.e. using "_" and "__" as variable names (which is possible in Ruby). Also I added some pointless statements to add some obfuscation.

Here is a short explanation:
The first method (called "_") takes an argument and counts from 0 to the argument .

The second method is a lambda expression (indicated by "->"), also called "_" (it is possible, since apparently the lambda namespace looks up the variables, not the method). The lambda has all the "logic" of the fizzbuzz evaluation.

The last statements calls the first method with the argument "100" and passes a block, which contains one senseless statement and then the call of the lambda function.


In hindsight those two hours were totally worth it.

#lang racket/base

(define (fizzbuzz-str start end [str ""])
(cond [(= start end) str]
[else
(fizzbuzz-str (add1 start)
end
(string-append str
(cond [(= 0 (modulo start 15)) "FizzBuzz"]
[(= 0 (modulo start 3)) "Fizz"]
[(= 0 (modulo start 5)) "Buzz"]
[else (number->string start)])))]))

(fizzbuzz-str 1 100)

am i hired? :^)
fizzbuzz = sequence [putStrLn x | x

There aren't any brackets in that code.

HAI 1.3

IM IN YR fizz UPPIN YR i TIL BOTH SAEM i AN 100
I HAS A i ITZ SUM OF i AN 1 BTW, ALL LUPZ START AT 0 :/
I HAS A mod3 ITZ NOT MOD OF i AN 3
I HAS A mod5 ITZ NOT MOD OF i AN 5

mod3, O RLY?, YA RLY, VISIBLE "Fizz"!, OIC
mod5, O RLY?, YA RLY, VISIBLE "Buzz"!, OIC

NOT EITHER OF mod3 AN mod5, O RLY?
YA RLY, VISIBLE i!
OIC

VISIBLE ""
IM OUTTA YR fizz

KTHXBYE

...

That's pretty impressive

#include #define BUZZZ int #define FIZZZ printf #define FIZZ for #define BUZZ if #define BZZ "\n" #define FUZZ return #define FIZZBUZZZ main #define FIZZZBUZZ "%d" #define FIZZBUZZ else #define BUZZFIZZ 3 #define FIZZFIZZ 5 #define BUZZBUZZ 100 BUZZZ FIZZBUZZZ(){BUZZZ fizzbuzz;FIZZ(fizzbuzz=BUZZFIZZ/BUZZFIZZ;fizzbuzz

say"Fizz"x!($_%3)."Buzz"x!($_%5)||$_ for 1..100

What would recruiters think of me if i did this in a job interview? genius or retard?

>off by one

you fail

fuck off

This is what I made with the wonderful technology
called MS Paint

void fizzBuzz() {
for (int i = 1; i

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

I seriously can't believe this is used as an interview question. Any kid learning how to code for the first time should be able to do this within the first two weeks.

That's exactly the point.

It's a simple test to weed out the people that apply for a programming job without even the simplest coding skills.

You think those people don't exist?
Behold, make room for the queen of Sup Forums:

>css-tricks.com/tales-of-a-non-unicorn-a-story-about-the-trouble-with-job-titles-and-descriptions/

post yours, faggot

Here is the excerpt:

>Interviewer: "Are you familiar with FizzBuzz?"
>Girl: "Ok, again to be honest, my JS knowledge is more regarding UI/UX based tasks. And I don't really understand the point of the question. Like, what's the use case? When would this come up in the role?"


The requirement of the job was:
>HTML5, CSS3, JavaScript.
>prefered: Experienced with Object Oriented JavaScript and modern JavaScript libraries such as Ember, Backbone, or Angular.

Any yet she can't write FizzBuzz.

>simple test to weed out
Why not ask something slightly more difficult? Now what's going to happen is normies will think FizzBuzz is a high bar for entry and an indication of high skill.

Reverse binary tree in 3 different assembly languages?

Swap two elements in an array?

People might be under stress. Coding under such stress is difficult for some people.

It's not like you solve the FizzBuzz and get the job, it's more a little starter to see if it's worth asking real questions. A real programmer would just fast forward through this and be more relaxed and comfortable afterwards.

IMO, a much better but still simple test of a candidate's logic/problem-solving capabilities.

### Functions ###
range = $(if $(filter $1,$(lastword $3)),$3,$(call range,$1,$2,$3 $(words $3)))
make_range = $(foreach i,$(call range,$1),$(call range,$2))
equal = $(if $(filter-out $1,$2),,$1)


### Variables ###
limit := 101
numbers := $(wordlist 2,$(limit),$(call range,$(limit)))

threes := $(wordlist 2,$(limit),$(call make_range,$(limit),2))
fives := $(wordlist 2,$(limit),$(call make_range,$(limit),4))

fizzbuzz := $(foreach v,$(numbers),\
$(if $(and $(call equal,0,$(word $(v),$(threes))),$(call equal,0,$(word $(v),$(fives)))),FizzBuzz,\
$(if $(call equal,0,$(word $(v),$(threes))),Fizz,\
$(if $(call equal,0,$(word $(v),$(fives))),Buzz,$(v)))))


### Target ###
.PHONY: all
all: ; $(info $(fizzbuzz))


Rate my FIzzBuzz

Pray tell where are the jobs who start wagecuck candidates off with FizzBuzz.

Hahaha, is this a makefile?

breddy gud

>Hahaha, is this a makefile?
Indeed

>breddy gud
Thanks

If the point is to weed people out early, why wouldn't you ask a more difficult question? Eventually all the normies getting rejected will be demotivated by the difficulty of the field and you'll have an even smaller application pool to cull in the future.

Didn't know GNU Make could be written in an almost functional way.