Fizz Buzz Interview Question

You have _ minutes to solve the most famous programming interview question in your favourite language:

>Print the numbers 1 to 100
>Next to every multiple of 3, print Fizz
>Next to every multiple of 5, print Buzz
>Next to every multiple of 3 and 5, print Fizz Buzz

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/NSFWRedditGif

FizzBuzz_1.java

class FizzBuzz {
public static void FizzBuzz1To50(){
System.out.println("1");
System.out.println("2");
System.out.println("Fizz");
System.out.println("4");
System.out.println("Buzz");
System.out.println("Fizz");
System.out.println("7");
System.out.println("8");
System.out.println("Fizz");
System.out.println("Buzz");
System.out.println("11");
System.out.println("Fizz");
System.out.println("13");
System.out.println("14");
System.out.println("FizzBuzz");
System.out.println("16");
System.out.println("17");
System.out.println("Fizz");
System.out.println("19");
System.out.println("Buzz");
System.out.println("Fizz");
System.out.println("22");
System.out.println("23");
System.out.println("Fizz");
System.out.println("Buzz");
System.out.println("26");
System.out.println("Fizz");
System.out.println("28");
System.out.println("29");
System.out.println("FizzBuzz");
System.out.println("31");
System.out.println("32");
System.out.println("Fizz");
System.out.println("34");
System.out.println("Buzz");
System.out.println("Fizz");
System.out.println("37");
System.out.println("38");
System.out.println("Fizz");
System.out.println("Buzz");
System.out.println("41");
System.out.println("Fizz");
System.out.println("43");
System.out.println("44");
System.out.println("FizzBuzz");
System.out.println("46");
System.out.println("47");
System.out.println("Fizz");
System.out.println("49");
System.out.println("Buzz");
}
}

Something something %3 %5 == 0 return jizzbuzz

nice try pajeet

FizzBuzz_2.java

classFizzBuzz {
public static void FizzBuzz51to100(){
System.out.println("Fizz");
System.out.println("52");
System.out.println("53");
System.out.println("Fizz");
System.out.println("Buzz");
System.out.println("56");
System.out.println("Fizz");
System.out.println("58");
System.out.println("59");
System.out.println("FizzBuzz");
System.out.println("61");
System.out.println("62");
System.out.println("Fizz");
System.out.println("64");
System.out.println("Buzz");
System.out.println("Fizz");
System.out.println("67");
System.out.println("68");
System.out.println("Fizz");
System.out.println("Buzz");
System.out.println("71");
System.out.println("Fizz");
System.out.println("73");
System.out.println("74");
System.out.println("FizzBuzz");
System.out.println("76");
System.out.println("77");
System.out.println("Fizz");
System.out.println("79");
System.out.println("Buzz");
System.out.println("Fizz");
System.out.println("82");
System.out.println("83");
System.out.println("Fizz");
System.out.println("Buzz");
System.out.println("86");
System.out.println("Fizz");
System.out.println("88");
System.out.println("89");
System.out.println("FizzBuzz");
System.out.println("91");
System.out.println("92");
System.out.println("Fizz");
System.out.println("94");
System.out.println("Buzz");
System.out.println("Fizz");
System.out.println("97");
System.out.println("98");
System.out.println("Fizz");
System.out.println("Buzz");
}
}

Sorry, of course all methods are in ONE class FizzBuzz.java.

public static void main(String[] args){
FizzBuzz1to50();
FizzBuzz51to100();
}

fizzbuzz n
| divBy 15 = "Fizz Buzz"
| divBy 3 = "Fizz"
| divBy 5 = "Buzz"
| otherwise = ""
where
divBy k = n `mod` k == 0

main = mapM_ printfbz [1..100]
where
printfbz i = putStrLn (show i " " fizzbuzz i)

public static void fizzbuzz(int max) {
assert max > 0;
for(int i = 1; i < (max + 1); i++) {
boolean printed = false;
if(i % 5 == 0) {
System.out.print("Fizz");
printed = true;
}
if(i % 3 == 0) {
System.out.print("Buzz");
printed = true;
}
if(!printed) {
System.out.print(i);
}
System.out.print("\n");
}
}

we java now

class FizzBuzz{
public static void main(String[] args){
int i =1;
while(i < 50){
System.out.print(i);
System.out.print("");
if(i%3==0) System.out.print("Fizz");
if(i%5==0) System.out.print("Buzz");
System.out.println();
i++;
}
}
}


Did i do well g?

If you can't do it in HolyC you fucking suck and you should kill yoruself stupid nigger cattle

github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

A for loop would have been a little nicer, but a functional fizzbuzz for 1 to 49.
Fuck I didn't read the OP and see that you had to print each number

done again in a loop.
class FizzBuzz{
public static void main(String[] args){
for(int i =1; i

npm install --save fizzbuzz-solver

var fizzbuzz = require('fizzbuzz-solver')

fizbuzz(0, 100);


I just started coding in node.js a couple of weeks ago and spent like 15 minutes searching for the right module with the least amount of bloat
i think it works alright

I'm still trying to figure out how functions and loops work but I am excited for the day I can do fizzbuzz.

>b-b-but I'm a web designer, not a math professor!




@import "compass/css3";

ul{
list-style-type:none;
}
li:nth-child(3n), li:nth-child(5n){
font-size:0px;
}

li:nth-child(3n):before{
font-size:16px;
content:"Fizz";
}
li:nth-child(5n):after{
font-size:16px;
content:"Buzz";
}




123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100

Trying to learn vim so I did another in Python3
for i in range(100):
print(i, end = " ");
if(i%3==0):
print("Fizz", end = " ");
if(i%5==0):
print("Buzz", end = " ");
print("\n");

u realize all ur answers are fucked?

ur supposed to print Fizz on 3
not
3Fizz

Read the OP again.
Thanks for coming along to the interview, you'll hear back from us if you've been successful.

if you don't know 'fizzbuzz' by heart and fall for the trap then you have no chance, idiot

>Print the numbers 1 to 100
>Next to every multiple of 3, print Fizz
The idiot is you, and the trap is not reading the question.

>solve the most famous programming interview question
says that
BEFORE the trap description
get rekt

#include

#define LEN 30

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

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

#include
using namespace std;

int main()
{
int counter=1;
while (counter

#include
#include

int main()
{

for(int i = 1; i

eval( hex2bin('20202020666f7265616368202872616e676528312c203130302920617320246c696e65293a0a0a202020202020202024627933203d20246c696e65202520333b0a202020202020202024627935203d20246c696e65202520353b0a0a202020202020202069662028212462793320262620212462793529207b7072696e74202246697a7a42757a7a223b7d200a2020202020202020656c736569662028212462793329207b7072696e74202246697a7a223b7d200a2020202020202020656c736569662028212462793529207b7072696e74202242757a7a223b7d200a2020202020202020656c7365207b7072696e7420246c696e653b7d0a20202020202020207072696e7420225c6e223b0a0a20202020656e64666f72656163683b' ) );

>"print numbers 1 to 100"
>prints range instead, 0 to 99
F, you don't even get a phonecall back.

for i in range(100):
i = i + 1
print(i, end = " ");
if(i%3==0):
print("Fizz", end = " ");
if(i%5==0):
print("Buzz", end = " ");
print("\n");

Holy kek Sup Forums is stupid as fuck!
Read the OP again faggots. That's why y'all are petty NEETS, can't even read. Sad.

#include
#define LEFT_BRACE {
#define RIGHT_BRACE }
#define LEFT_BRACKET [
#define RIGHT_BRACKET ]
#define LEFT_PARENTHESIS (
#define RIGHT_PARENTHESIS )
#define SEMICOLON ;
#define COMMA ,
#define EQUALS =
#define IS_EQUAL_TO ==
#define IS_NOT_EQUAL_TO !=
#define IS_LESS_THAN <
#define IS_GREATER_THAN >
#define IS_LESS_THAN_OR_EQUAL_TO =
#define MODULUS %
#define INCREMENT ++
#define DECREMENT --
#define AND &&
#define OR ||

int main LEFT_PARENTHESIS RIGHT_PARENTHESIS
LEFT_BRACE
int i SEMICOLON
for LEFT_PARENTHESIS i EQUALS 0 SEMICOLON i IS_LESS_THAN_OR_EQUAL_TO 100 SEMICOLON i INCREMENT RIGHT_PARENTHESIS
LEFT_BRACE
if LEFT_PARENTHESIS i MODULUS 3 IS_NOT_EQUAL_TO 0 AND i MODULUS 5 IS_NOT_EQUAL_TO 0 RIGHT_PARENTHESIS
printf LEFT_PARENTHESIS "%d" COMMA i RIGHT_PARENTHESIS SEMICOLON
if LEFT_PARENTHESIS i MODULUS 3 IS_EQUAL_TO 0 RIGHT_PARENTHESIS
printf LEFT_PARENTHESIS "Fizz" RIGHT_PARENTHESIS SEMICOLON
if LEFT_PARENTHESIS i MODULUS 5 IS_EQUAL_TO 0 RIGHT_PARENTHESIS
printf LEFT_PARENTHESIS "Buzz" RIGHT_PARENTHESIS SEMICOLON

printf LEFT_PARENTHESIS " " RIGHT_PARENTHESIS SEMICOLON
RIGHT_BRACE

printf LEFT_PARENTHESIS "\n" RIGHT_PARENTHESIS SEMICOLON
return 0 SEMICOLON
RIGHT_BRACE

In vim:
i1qqYpq98@qqq0C Buzz5kq19@q2jqq0cwFizz3jq32@q:%s/ //

public static void main(string []args){
int i;

if (i == "BUZZ")
system.out.println(buzzfizz)
if (i == "FIZZ")
system.out.println(fizzbuzz)

for(i = 0; i < 100; i++)
system.out.println((int)i)

return void
}

Obligatory.

He wrote that crap?

One line in bash
curl "s3.amazonaws.com/fizzbuzz/output"

What are some other interview questions?

Also is FizzBuzz just a meme or employers actually use it as a test?

I don't understand why would you try to get a job involving programming if you can't solve this.

...

@echo off
echo 1
echo 2
echo 3
echo Fizz
echo 4
echo 5
echo Buzz
echo 6
echo 7
echo 8
echo 9
echo Fizz
echo 10
echo 11
echo 12
echo 13
echo 14
echo 15
echo Fizz Buzz

>invert a binary tree
>where do you see yourself in 5 years
>what can you contribute to our company
>fizzbuzz, then fizzbuzz without modulo
>would you pull the lever of the trolley problem
>write a program that prints out the password to your facebook account backwards
>the user X killed himself under mysterious circumstances: what do you do with the leftover data


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

i see myself working at your company :^)

why would you like to work for our company

> I have seen many comments here that are unnecessarily harsh or rude. Rudeness adds nothing constructive to the conversation so I’m perfectly okay with seeing rude, harsh or nonconstructive comments removed.
> There are some people writing that if you can’t “FizzBuzz” you don’t belong in this industry. That’s a harsh thing to say and it’s simply not true.

Gets me every time.

>fizzbuzz without modulo
Why?

> There are some people writing that if you can’t “FizzBuzz” you don’t belong in this industry. That’s a harsh thing to say and it’s simply not true.

If you can't write a FizzBuzz you're basically mentally challenged

Why not?
#include

int main() {
size_t f = 0, b = 0, to = 20;
for (size_t i = 1; i 2 ? 0 : f) == 2;
int bt = (b = b > 4 ? 0 : b) == 4;
printf("%s", ft ? "Fizz" : "");
printf("%s", bt ? "Buzz" : "");
printf(ft || bt ? "\n" : "%zu\n", i);
}
}

to prove you didn't only memorize the first google result and/or can think up multiple ways to solve the problem

for i in range(1,101):
fb = ''
if i % 3 == 0:
fb += 'Fizz'
if i % 5 == 0:
fb += 'Buzz'
print(fb or i)

just check if there is a decimal. it hardly makes the problem more complicated.

in a stressful situation like a job interview, you might freeze on the one fizzbuzz solution or you might still be able to think around the obstacle. its not about complexity

literally the easiest FizzBuzz I've seen
>you're hired

The basic bitch version

for x in range(1, 101):
if x % 3 == 0 and x % 5 == 0:
print('FizzBuzz')
elif x % 3 == 0:
print('Fizz')
elif x % 5 == 0:
print('Buzz')
else:
print(x)

for (var i = 1; i

interesting way of doing it

It makes it easy to change the fizz/buzz parameters, and it's very compact.

(I've also done this before)

Nice job, but hard to read. I know the language, but I still had to do a double take to understand this simple code.

Feel free to entertain yourselves with trivial convolutions if you wish, but it's still just the integer rings modulo 5 and 3. You're not going to find a novel way of doing it, just ways of adding entropy to the answer.

>>would you pull the lever of the trolley problem
I would walk out of my job the first day anyone referenced a meme irl

VBA

debug.print "1" & vbnewline & "2" & vbnewline & "fizz" & vbnewline & "4" & vbnewline & "buzz" & vbnewline & "fizz" & vbnewline & "7" & vbnewline & "8" & vbnewline & "fizz" & vbnewline & "buzz" & vbnewline & "11" & vbnewline & "fizz" & vbnewline & "13" & vbnewline & "14" & vbnewline & "fizzbuzz" & vbnewline & "16" & vbnewline & "17" & vbnewline & "fizz" & vbnewline & "19" & vbnewline & "buzz" & vbnewline & "fizz" & vbnewline & "22" & vbnewline & "23" & vbnewline & "fizz" & vbnewline & "buzz" & vbnewline & "26" & vbnewline & "fizz" & vbnewline & "28" & vbnewline & "29" & vbnewline & "fizzbuzz" & vbnewline & "31" & vbnewline & "32" & vbnewline & "fizz" & vbnewline & "34" & vbnewline & "buzz" & vbnewline & "fizz" & vbnewline & "37" & vbnewline & "38" & vbnewline & "fizz" & vbnewline & "buzz" & vbnewline & "41" & vbnewline & "fizz" & vbnewline & "43" & vbnewline & "44" & vbnewline & "fizzbuzz" & vbnewline & "46" & vbnewline & "47" & vbnewline & "fizz" & vbnewline & "49" & vbnewline & "buzz" & vbnewline & "fizz" & vbnewline & "52" & vbnewline & "53" & vbnewline & "fizz" & vbnewline & "buzz" & vbnewline & "56" & vbnewline & "fizz" & vbnewline & "58" & vbnewline & "59" & vbnewline & "fizzbuzz" & vbnewline & "61" & vbnewline & "62" & vbnewline & "fizz" & vbnewline & "64" & vbnewline & "fizz" & vbnewline & "fizz" & vbnewline & "67" & vbnewline & "68" & vbnewline & "fizz" & vbnewline & "buzz" & vbnewline & "71" & vbnewline & "fizz" & vbnewline & "73" & vbnewline & "74" & vbnewline & "fizzbuzz" & vbnewline & "76" & vbnewline & "77" & vbnewline & "fizz" & vbnewline & "79" & vbnewline & "buzz" & vbnewline & "fizz" & vbnewline & "82" & vbnewline & "83" & vbnewline & "fizz" & vbnewline & "buzz" & vbnewline & "86" & vbnewline & "fizz" & vbnewline & "88" & vbnewline & "89" & vbnewline & "fizzbuzz" & vbnewline & "91" & vbnewline & "92" & vbnewline & "fizz" & vbnewline & "94" & vbnewline & "buzz" & vbnewline & "fizz" & vbnewline & "97"

Cont.

9 out of 10 CS majors cannot fizzbuzz

from india? otherwise i think that's bullcrap.

cont.
& vbnewline & "98" & vbnewline & "fizz" & vbnewline & "buzz"

I used to feel the same way until i memorized this "new" syntax (new to me) and it helped me read and write more advanced JS

#include

#define fb(x,i,s) ((x)[i] ? (s) : "")
const int fizz[] = { 0,0,1,0,0,1,0,0,1,0,0,1,0,0,1 };
const int buzz[] = { 0,0,0,0,1,0,0,0,0,1,0,0,0,0,1 };
const size_t to = 100;

int main() {
size_t cnt = 0;
for (size_t i = 1; i = 15 ? 0 : cnt;
printf("%s%s", fb(fizz,cnt,"Fizz"), fb(buzz,cnt,"Buzz"));
printf(!fizz[cnt] && !buzz[cnt] ? "%zu\n" : "\n", i);
}
}

keep in mind this is on a whiteboard no stack overflow allowed

def mark(lst, multiple, word):
for i in range(1, 101 // multiple + 1):
lst[i * multiple - 1] += word

res = ["{} ".format(i) for i in range(1, 101)]
mark(res, 3, "Fizz")
mark(res, 5, "Buzz")


Depends on your interpretation of "next to". I assumed it was literally next to it, and not after it on a separate line.

Of course
print(res)

for i in range (1,101):
v="";
if(i%3==0): v+="Fizz"
if(i%5==0): v+="Buzz"
print(i,"\t",v)

>Next to every multiple of 3 and 5, print Fizz Buzz

Why putting a space between Fizz and Buzz ?

> one-line if
Read PEP please

int i;
for(i = 1; i< 101; i++){
printf("%d ", i);
if(!(i%3)) printf("Fizz");
if(!(i%5)) printf("Buzz");
}

inside int main and #include stdio and all that jazz

oh God, which one is right???? do I follow the potentially buggered instructions or do I follow convention???? I JUST WANT TO BE PAID FOR MY SERVICES
>Thanks for coming along to the interview, you'll hear back from us if you've been successful.

I think the culture and stated goals on your website are a great fit for my interests and mindset

for i in range(1,101):
if (i/3.0).is_integer() and (i/5.0).is_integer():
print "FizzBuzz"
elif (i/3.0).is_integer():
print "Fizz"
elif (i/5.0).is_integer():
print "Buzz"
else:
print i

good one

even still... by the time you graduate any cs program in the US you should have seen modulo, the idea that you wouldn't have is ridiculous beyond belief

I've literally only heard students saying this, I've never heard degree holders claiming that people can't fizzbuzz. You might find some funny anecdotes on reddit or something but beyond that the idea that people can't fizzbuzz is laughable. This is there to weed out the complete fakes and nothing else.

threes = {*range(3,101,3)}
fives = {*range(5,101,5)}
all_ = {*range(1,101)}

fizzbuzz = threes & fives
fizz = threes - fizzbuzz
buzz = fives - fizzbuzz
rest = all_ - threes - fives
concat = [[i, str(i)] for i in rest] + [[i, "fizz"] for i in fizz] + [[i, "buzz"] for i in buzz] + [[i, "fizzbuzz"] for i in fizzbuzz]
concat.sort(key=lambda x: x[0])

print("\n".join((i[1] for i in concat)))

If we're taking the OP problem word for word, there should be a space in between 'Fizz' and 'Buzz' for the multiples of 3 and 5, you all fail.

>Fix it faggots

...

newfag here how do i put the code panel in my post?

[code ] code here [ /code]

without spaces in the tag

thanks

for(i in 1:100){

ifelse(!(i %% 15),print(paste(i,"Fizz Buzz")),
ifelse(!(i %% 3),print(paste(i,"Fizz")),
ifelse(!(i %% 5),print(paste(i,"Buzz")),print(i))))

}