FizzBuzz thread

Can we get a FizzBuzz thread going?

I'm a Ruby guy, total PHP noob, how's this for a PHP solution? Marks out of 10?

Other urls found in this thread:

joelgrus.com/2016/05/23/fizz-buzz-in-tensorflow/
twitter.com/AnonBabble

0
Where is the fizzbuzz

do you even code?

....what? The code is literally there

If you run that code it works fine, the first fifteen lines are this:

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz

Shameless bump

def fizzBuzz(i: Int): String = {
if (i % 15 == 0)
"FizzBuzz"
else if (i % 3 == 0)
"Fizz"
else if (i % 5 == 0)
"Buzz"
else
i.toString
}

(1 until 100).map(fizzBuzz _ andThen println)

>not fizzbuzzing in tensorflow
>joelgrus.com/2016/05/23/fizz-buzz-in-tensorflow/


go to bed pajeet

So I got this right.. you know Ruby and want to learn PHP ?

Just when you think you've seen it all..

is that supposed to be functional?
dont use map for side-effects, use foreach.

> if (empty($string))
> $string .= $i;

There is no need use 'empty()'

if ($string == "")


Then it should work fine.

Been a while since I PHPed. Don't even know if this'll work.

>employing a fucking string variable for simple number comparisons

Nice piece of bloat you coded there Ranjeep, do you work for Microsoft by any chance?

I don't understand the obsession with this task

I wish Sup Forums stopped with this fizz buzz meme already. it's literally hello world 1.01. why don't you pick something that's simple, but involves something more than a single logical branch, like the sieve of Eratosthenes

rate

#include

int main(){
int n=120,array[999],i;

// generate list of integers from 2 to n
for(i=2;i

>go to job interview
>actually get the fizzbuzz question

Never done one before, but would this be correct?

void main(int argc, char * argv)
{
int iter = 0;

while (iter

We’re not here to do your homework. Google it you retard.

fizzBuzz i = if null desc then show i else desc where desc = concat [label | (j,label)

One line python reporting in :)
for x in range(100):print"fizz"*(x%3==0)+"buzz"*(x%5==0)or x

>So I got this right.. you know Ruby and want to learn PHP ?

You're correct.

Yes Ruby is definitely way fucking better, but I'm NEET right now and there are more jobs in PHP.

I keep applying to PHP jobs so I should probably fucking know some PHP.

It's not my fault they don't use superior Rails

I suppose that's true but is there an obvious advantage? Maybe it's just because I'm used to Ruby where I would use string.empty?

import java.util.pajeet;

public class FizzBuzz {

public static void main(String[] args) {
System.out.println(pajeet.fizzBuzz(100));
}
}

How could you fuck up such a short code? I guess this is representative of how retarded FizzBuzz circlejerkers are.

Alright then, is this better?

Lol

What did i fuck up?

it starts by printing fizzbuzz
doesn't go to 100

we'll call you

oh haha sorry my bad here's an update
for x in range(101):print"fizz"*(x%3==0)+"buzz"*(x%5==0)or x

>it starts by printing fizzbuzz
that's not wrong if you start counting at 0.

I'm not sure what the real FizzBuzz problem states, the other guy's implementation is correct if you view numbers from 0 to 99.

OP should have posted the wording of the FizzBuzz problem

everyone knows the fizzbuzz problem is 1-100, people just make mistakes and then backpedal it
"i-i'm not like those other hundreds of thousands of people who apply for programming jobs and can't fizzbuzz, I s-swear! this common stupid mistake I made doesn't count!"

I don't really see a reason to start at 1, if you would want to just do integers 1 - 100 i guess you would do range(1, 101). Sorry for the misunderstanding, been writing python as my first programming language for a week now ;). Would love some not to harsh criticism.
here's 2 functions that could be put to use in a for loop that i made up,

def fizzbuzz(x):
if x % 15 == 0:
print "FizzBuzz"
elif x % 5 == 0:
print "Buzz"
elif x % 3 == 0:
print "Fizz"
else:
print x


def fizzbuzz2(x):
if x % 5 == 0 and x % 3 != 0:
print "buzz"
elif x % 3 == 0:
if x % 5 == 0:
print "FizzBuzz"
else:
print "Fizz"
else:
print x

People are too used to for loops beginning with i = 0

yes, that's what the fizzbuzz test is about, your attention to detail.

lol at 4channers "almost" getting fizzbuzz right and thinking it counts, that they aren't as dumb as those other people.

#include

int main (void)
{
char s[42] = "FizzBuzz\0Fizz";
size_t o[4] = {15,9,4,0};
unsigned a = 4;
unsigned b = 1;

for (int i = 1; i

indentations fucked up sorry guys

function fizzBuzz(n) {
function generate(array, n) {
if (n === 1) {
array.push(n);
return array.reverse();
}

if (n % 15 === 0) {
array.push('FizzBuzz');
} else if (n % 5 === 0) {
array.push('Buzz');
} else if (n % 3 === 0) {
array.push('Fizz');
} else {
array.push(n);
}

return generate(array, n - 1);
}

if (n === 0 || n < 1) {
return [];
}

return generate([], n);
}

console.log(fizzBuzz(100).join('\n'));

I failed FizzBuzz, I admit it. I was asked that as an interview question. I studied hard for my interview but I forgot about the mod operator and totally fumbled my way through the interview. I am now the Senior Web Developer and turned out to be a great asset to the company. But you wouldn't have known that from my FizzBuzz results. I also didn't have 'Computer Science' as a Major. Couple strikes. However they took a chance on me.
Since then I've been able to interview others and I look for different things than FizzBuzz compliance. I want to see how they solve problems in general. I want to see if they have any passion for what they do. I want to see things they've developed.

function *every(n, s) {
yield* new Array(n - 1).fill('');
yield s;
yield* every(n, s);
}


function fizzBuzz(n) {
let fizz = every(3, 'fizz');
let buzz = every(5, 'buzz');
for (let i = 1; i

>All these FizzBuzz threads recently.

Is it college finals week or something? Do your own damn work.

#include

int main()
{
int i = 1;

counter:
printf("%d, ", i++);
if(i > 100) goto exit;
if(i % 3 == 0) goto fizzer;
if(i % 5 == 0) goto buzzer;
goto counter;

fizzer:
printf("Fizz");
if(i++ % 5 == 0) goto buzzer;
printf(", ");
if(i > 100) goto exit;
if(i % 5 == 0) goto buzzer;
if(i % 5 && i % 3) goto counter;
goto fizzer;

buzzer:
printf("Buzz, ");
if(++i > 100) goto exit;
if(i % 3 == 0) goto fizzer;
if(i % 5 && i % 3) goto counter;
goto buzzer;

exit:
return 0;
}

>if
>if
>if

Fucking hell, sure is scrub in here.

Of course it did, you forgot to use a code block.

Protip: If you write a FizzBuzz code that either
>Uses more than 200 modulo operations
>Isn't in a well-established programming language
>Lacks a documentation
then you will not get the job.

Who cares. I already have a job. I'm doing these for the lulz.

>I forgot about the mod operator
You could have easily done it without the mod operator.

for (int i = 1, fizz = 1, buzz = 1, i

Fixed indentations
def fizzbuzz(x):
if x % 15 == 0:
print "FizzBuzz"
elif x % 5 == 0:
print "Buzz"
elif x % 3 == 0:
print "Fizz"
else:
print x


def fizzbuzz2(x):
if x % 5 == 0 and x % 3 != 0:
print "buzz"
elif x % 3 == 0:
if x % 5 == 0:
print "FizzBuzz"
else:
print "Fizz"
else:
print x

for x in range(1, 101):
fizzbuzz2(x)
fizzbuzz(x)


thanks

What is FizzBuzz?

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

It's prob shit.
public class fizzbuzz{
public static void main(String[] args){
for(int i = 1; i

But what IS it? Is there a way to explain it to someone who doesn't know any programming languages?

count up to a hundred, but if the number is div by 3 say fizz and if it's by 5 say buzz and if it's both say fizzbuzz

shit forgot to reply

how does that work? I understand python's array notation, but I don't understand the numbers behind those equations.

I can't comment on the speed of using 'empty()' compared to '$foo == ""' since I can't be assed to test. I think they'll be similar, nevertheless speed doesn't matter too much unless it's very significant (by maybe a few seconds more than milliseconds).

Though in programming languages that use C-style (null-terminated) strings, comparing to "" will be faster.

Even though built-in functions are there to make it easy for programmers, you should NOT rely on them entirely.

IF you do:
$kek = "0123";

echo empty($kek) ? "The string is empty" : "The string is NOT empty";


It will print 'The string is NOT empty' as expected.

Though if you do
$kek = "0";

echo empty($kek) ? "The string is empty" : "The string is NOT empty";


It will print 'The string is empty' this is incorrect.

Therefore

This is a reason why it's sometimes better just use operators than call functions and procedures to do simple shit.

#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);
}

return no[7] == '0' || no[7] == '3' || no[7] == '6' || no[7] == '9';
}

int divisible_by_5 ( char* no )
{
return no[7] == '0' || no[7] == '5';
}

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

*slow clap*

Is FizzBuzz the only thing Sup Forums is capable of programming?

#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

No parentheses after print, it goes from 0 to 99 and that or means absolutely nothing. FizzBuzz circlejerkers confirmed for Pajeet-tier code monkeys.

I have no clue. I just copypasted. This is called FizzBuzz of the Christ.

Sup Forums is looking for work.

>Is FizzBuzz the only thing Sup Forums is capable of programming?

Does that surprise you?

#include

int main() {

int i;
while( i < 101 ) {
i % 15 == 0 ? printf("FizzBuzz\n") : i % 3 == 0 ? printf("Fizz\n"): i % 5 == 0 ? printf("Buzz\n"): printf("%d\n", i);
i++;
}

return 0;
}

Program FizzBuzz;
Uses sysutils;
Var
i, n: Integer;
fbarr: Array [1..15] of String[9] = ('%', '%', 'Fizz', '%', 'Buzz', 'Fizz', '%', '%', 'Fizz', 'Buzz', '%', 'Fizz', '%', '%', 'Fizz Buzz');
Begin
If Length(ParamStr(1)) = 0 Then
n := 30
Else
n := StrToInt(ParamStr(1));

For i := 0 To n-1 Do Begin
If fbarr[(i Mod 15) + 1] = '%' Then
Write(IntToStr(i+1))
Else
Write(fbarr[(i Mod 15) + 1]);
If i n-1 Then Write(', ');
End;
WriteLn('.');
End.

open Printf;;
open List;;

let rec range a b =
if a > b then []
else a :: range (a+1) b;;

let num = range 1 100 in
let rec aux x =
match (x mod 3, x mod 5) with
| (0, 0) -> "FizzBuzz"
| (0, _) -> "Fizz"
| (_, 0) -> "Buzz"
| (_, _) -> string_of_int x in
map (printf "%s\n") (map aux num)


get on my level

Glorious OCaml or filthy F#?

lmao
>functional progamming
>somehow non tail recursion is bad practice

I rewrite your whole code to teach you user
open Printf;;
open List;;

let rec iter_range f a b =
if a > b then
()
else
begin
f a;
iter_range f (succ a) b
end

let _ =
iter_range
(fun x ->
let s =
match (x mod 3, x mod 5) with
| (0, 0) -> "FizzBuzz"
| (0, _) -> "Fizz"
| (_, 0) -> "Buzz"
| (_, _) -> string_of_int x in
print_endline s)
1 100

stupid/10

fizzbuzz x
| x `mod` 15 == 0 = putStrLn "FizzBuzz"
| x `mod` 5 == 0 = putStrLn "Buzz"
| x `mod` 3 == 0 = putStrLn "Fizz"
| otherwise = print x

main = mapM_ fizzbuzz [1..100]

As long as it does a fair amount of numbers and the business logic is sound, it really doesn't matter what range of numbers it does.

this is pretty kek

IF YOUR CODE HAS
15
or
fizzbuzz
IN IT, THEN YOU ARE BAD AT PROGRAMMING.

No it's not, I just saw all the threads recently and wanted to see what people thought of my noob PHP solution

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

Why?

Learn to allocate dynamic memory

because you're already checking for division by 3 & 5, and already printing fizz & buzz.
You don't need a special case for 15.

You forgot performance.

performance IS the reason for removing the 3rd check.

These are literally the gayest threads.

But I need to show off my extra optimized fizzbuzz.
(loop for i from 1 to 100 do
(print (case (gcd i 15)
(3 "fizz")
(5 "buzz")
(15 "fizzbuzz"))))

That might be the worst Scala I've ever seen

You should compare the different solutions.

import random

for i in range(0, 100):
if not i % 15:
random.seed(1178741599)
print [i+1, "Fizz", "Buzz", "FizzBuzz"][random.randint(0,3)]


:^)

what the fuck

rate
for i in range(1, 101):
if (i % 3) and (i % 5):
print(i)
continue
if i % 3:
print("Fizz", end = "")
if i % 5:
print("Buzz", end = "")
print()

>hundreds of questions on project euler to make threads about.
>huuurrr le fizz buzz maymay thread

STOP.

>those other hundreds of thousands of people who apply for programming jobs and can't fizzbuzz


Sounds like jobs need to stop using some retarded arbitrary test and try actual real world scenarios to find out the competency of people coding for real life scenarios instead of ones thought up for the sole purpose of being difficult and confusing and useless.

thats wrong you dolt

oops meant

for i in range(1, 101):
if (i % 3) and (i % 5):
print(i)
continue
if i % 3 == 0:
print("Fizz", end = "")
if i % 5 == 0:
print("Buzz", end = "")
print()

still wrong senpai

not him but it seems to work when I tested it

Wow for a moment I actually believed this worked.

Good thing it isn't an actual program and is just designed to waste peoples time on an trick questions.

you didn't get the concept right, the code works, but it doesn't do what is asked

> conditional logic

whichfizz = fn
(0, 0, _) -> "FizzBuzz"
(0, _, _) -> "Fizz"
(_, 0, _) -> "Buzz"
(_, _, n) -> n
end

fizzbuzz = fn (n) ->
whichfizz.(rem(n, 3), rem(n, 5), n)
end

IO.inspect Enum.map(1..100, fizzbuzz)

wait what

A Haskell one-liner I made a few months ago.

mapM_ print [if x `mod` 15 == 0 then "FizzBuzz" else if x `mod` 5 == 0 then "Fizz" else if x `mod` 3 == 0 then "Buzz" else show x | x

Oh, and I was just starting to learn haskell at the time, so I'm sure this can be shortened by like, half or something.

I'm not a haskell guru myself but generally using if then else is less preferred to guards, I think. A list comprehension also isn't really needed for this

if i mod 3 == 0 and i mod 5 == 0, print FizzBuzz

when it doesn't get in any of the 3 contidions (mod 3 and 5, mod 5, mod 3), then print i

fizz 0 0 _ = "Fizzbuzz"
fizz 0 _ _ = "Fizz"
fizz _ 0 _ = "Buzz"
fizz _ _ n = show n

fizzbuzz = [(fizz (rem x 3) (rem x 5) x) | x