Fizzbuzz

you have 2 minutes to write a program that does the following:
>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”.
and then submit in post box.

GO!

Other urls found in this thread:

pastebin.com/7rPfd1Xv
godbolt.org/g/j46oU7
pst.moe/paste/ozkgxy
twitter.com/SFWRedditVideos

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

kys faggot

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

public class Fizzbuzz {

public static void main(String[] args){
for(int i=1; i

#include

main()
{
int x=0;
while(x

#include

int main(void) {
int i = 1;
while(i++

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

>>Not using if/elseifs
Hardly

for i in range(1, 101):
print({i % 15: "FizzBuzz"}.get(0, {i % 3: "Fizz", i % 5: "Buzz"}.get(0, i)))

for(int i = 1; i < 101; i++){
if(i %3 != 0 && i % 5 != 0) cout

void PrintFizzBuzz(int limit) {
StringBuilder sb = new StringBuilder();
for (int i = 1; i

var i=0;while(i++

var i=0;while(i++

This, but specify capacity of 8 for the string builder. Also verify limit is a positive integer.

OMG, MATH!

well, specify capacity that can hold the largest int, so 10

js, one line

eval(new Array(99).fill(1).map((e,i)=>i+1).reduce((a,e) => a+"console.log('"+(((e%3==0)?'fizz':'')+((e%5==0)?"buzz":'') || e)+"');",''))

am I hired?

for i in range(1, 101):
print("Fizz"*(i%3) + "Buzz"*(i%5) or i)

for(int i = 1; int < 101; i++){
if (i % 3){
System.out.print("Fizz");
}
if (i % 5) {
System.out.print("Buzz");
} else{
System.out.print(i);
}
}

kek this was the "programming part" of our second exam in my intro to computer programming class. had no idea it was a meme until like a year later on here - some feminist web designer was bitching about it in one of her blogs because they gave it to her at the end of her job interviews or something lmao

Buzz
FizzBuzzBuzz
FizzFizzBuzzBuzzBuzz
BuzzBuzzBuzzBuzz
etc.

Did you mean for i in range(1, 101):
print("Fizz"*(i%3==0) + "Buzz"*(i%5==0) or i)
? Still, a neat idea.

Yeah I just forgot the == 0 parts in both. If you add that then I believe they are both correct.

for(i in new Array(100).fill(1)){console.log(i%3===0?i%5===0?"fizzbuzz":"fizz":i%5===0?"buzz":i)}
15min

a program that does the following:
>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”.


what do i win

>for i in range(1, 101):
> print("Fizz"*(i%3) + "Buzz"*(i%5) or i)
this is python right? Its fucking hideous.
Here is my correction:
for i in range(100): #yes, you can set the final integer and nothing else for an array
print("Fizz"*(i%3) + "Buzz"*(i%5) or i) #This entire segment doesn't accomplish the task.

Output should be:
1, 2, fizz, 4, buzz ... 13, 14, FizzBuzz, 16...
What you are doing instead is repeating the string Fizz or Buzz a multitude of times, and concentiating the strings together, which would provide the output:
FizzBuzz
FizzFizzBuzzBuzz
BuzzBuzzBuzz
FizzBuzzBuzzBuzzBuzz
FizzFizz
Buzz

The correct way that i think you were aiming for is:
for i in range(100):
print("Fizz" if i%3 == 0 else "Buzz" if i%5 == 0 else "FizzBuzz" if i%15 == 0 else i) #linear conditional :^)
[/code

>what do i win
You get to masturbate to your superiority compared to 99.9% of "programmers"?

why use for? why not map? learning lambdas would really help you out, there's not hard and extremely useful.

for i in {1..100}; do [ $(($i%3)) != 0 ] && [ $(($i%5)) != 0 ] && echo -n $i || { [ $(($i%3)) = 0 ] && echo -n fizz; [ $(($i%5)) = 0 ] && echo -n buzz; }; echo; done

Echo fizzbuzz

for i in `seq 1 100`; do [ $(($i%3)) != 0 ] && [ $(($i%5)) != 0 ] && printf $i || { [ $(($i%3)) = 0 ] && printf fizz; [ $(($i%5)) = 0 ] && printf buzz; }; echo; done

#include
#include

int main( int argc, char **argv )
{
for( int i = 1; i

//Fizzbuzz
//

#include

using namespace std;

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

if((i%3 == 0) && (i%5 == 0))
{
cout

and messed up the [/code] closer. nice

You wasted a lot of time blabbering about a typing error I already addressed

for(i=1;i

...

explain

Impressive. I've never seen a Makefile version of fizzbuzz before.

press F12, enter it into the console

not the ref user but I can explain
standard for loop, i 1 through 100
if "i modular 3" is 0 it goes to false (2nd option after ternary operator) if "i modular 3" is any other number it's true (1st option after ternary operator) which means if both i%3 and i%5 gives a non-zero number, then the number is neither a multiple of 3 or multiple of 5. then you simply stack ternary operators on top of that.

how does this work?

Might be clearer. i%3 is 0 (false) if i is divisible by 3.
for(i=1;i

Good job user but we're looking for something a little more efficient here.

Can you code this with a runtime faster than O(N)

I meant: why do you use a loop

> Also verify limit is a positive integer.

The for loop already does that you stupid faglord

there you go sir, O(1):

HIRED!

I'm sending you over to HR. Training starts tomorrow!

Ok I can do fizzbuzz so I'm not that dumb but how would I do the string timecode into seconds?

I want 150k tho

they probably wanted regex or array query

you bastard

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

maps numbers between 1 and 100 to slices of "fizzbuzz" string

#include
int main() { const char *fuzz[] = {"%i\n", "fizz\n", "buzz\n", "fizzbuzz\n"}; int i = 0; for (i = 1; i < 101; i++) printf(fuzz[!(i % 3) + (2 * !(i % 5))], i); }

>fizzbuzz in C in one line

#define ITERATOR size_t
#define START for(IT=1;IT

>one line
Going through your program and deleting all the line break characters doesn't make your program one line.

#include
int main() {
const char *fuzz[] = {"%i\n", "fizz\n", "buzz\n", "fizzbuzz\n"};
int i = 0;
while (++i < 101) printf(fuzz[!(i % 3) + (2 * !(i % 5))], i);
}

Cleaner version.

>int i = 0; for (i = 1;

your license to live has been revoked

for (int i = 1; i < 101; i++) {
Console.Write((i%3==0 ? (i%5==0 ? "FizzBuzz" : "Fizz") : (i%5==0 ? "Buzz" : i)) + " ");
}

Feedback welcome.

Yeah, I caught that after I posted it. I initially needed it initialized to 0, and then switched to a for loop and set it to one there, but forget to take off the "= 0" from before. Kill me.

I personally find nested ternaries to become a clusterfuck, but the logic is sound. I'd probably ask why you're not using if/else branches, as they'd be logically equivalent and easier to read.

print('1')
print('2')
print ('3')
Etc

cs grad nene pic

Unfortunately Sir my efficient and complicated program won't fit in the form you provided, so I am sending you a link with code pasted.

Please do the needful.

pastebin.com/7rPfd1Xv

I did something like that for an interview at Cerner in Kansas City and the guy was saying it was wrong for some reason. at first he thought there would be 2 lines for FizzBuzz, but I showed him that I used print instead of println and had a /n at the end of the loop, but then he said that was tricky and unnecessarily complicated. I didn't get the job

oh god I love how you got th Engrish part right too. reminds me of my old job...

our web application was fucking doomed from the start.

for(i=1;i

>150k
I'm so sorry but the board has actually decided to go with Chadha Rajeev Kapoor. At 30k he is a steal.

npm install fizzbuzz

"ok Google, solve FizzBuzz"

Ah yes thankyou sir for the opportunity. I will get started by ignoring all git conflicts and refusing to safely merge when I am pushing my commits

program fizzbuzz(output);
var
i: integer;
begin
for i := 1 to 100 do
if i mod 15 = 0 then
writeln('FizzBuzz')
else if i mod 3 = 0 then
writeln('Fizz')
else if i mod 5 = 0 then
writeln('Buzz')
else
writeln(i)
end.

`ECHO "op is a faggot"`

I don’t understand how this is even possible.... Make can’t even do any form of arithmetic. I feel like a brainlet having encountered God’s truth here.

...

main = let (|>) = flip ($) in
zipWith (++) (join$repeat ["","","fizz"]) (join$repeat ["","","","","buzz"])
|> zipWith (\x y -> if null y then show x else y) (iterate (+1) 1)
|> unlines
|> putStrLn

I'm lazy

10 CLS
20 FOR A=1 TO 100
30 PNUM=1
40 IF (A MOD 3)=0 THEN PRINT "FIZZ";:PNUM=0
50 IF (A MOD 5)=0 THEN PRINT "BUZZ";PNUM=0
60 IF PNUM=1 THEN PRINT A;
70 PRINT " ";
80 NEXT
90 PLAY "CDEFGAB"

>90 PLAY "CDEFGAB"
the nostalgia is real

As it is the lack of the : at line 50.

I've used them here for literally no reason other than being faster to type (purely IMO territory).

>his fizzbuzz isn't in nice helvetica

7 dup scale
5 110 translate
0 0 moveto
/Helvetica findfont
1 scalefont
setfont

1 1 100 {
dup -1 mul 1 add 0 exch moveto
dup /n exch 3 string cvs def
dup 5 mod 0 eq
{ /n () def { (Buzz) show } } { {} } ifelse
exch 3 mod 0 eq
{ /n () def { (Fizz) show } } { {} } ifelse
exec
exec
n show
} for

showpage

cd code
cd..
pwd
cd..
cd ..
ls
cd code
cd ..
cd ..

I don't know javascript, but can someone tell me how this is O(1)?
Is it just as fast to create 100 elements as it is to create 1,000,000?
I could just be getting big O notation wrong.

Javascript:
new Array(100).fill(0).map((x,i)=>i+1).map(n=>((n%3===0?'fizz':'')+(n%5===0?'buzz':''))||n).join(' ');


To be fair, I spent more than 2 minutes on it. But fuck it, I know how to write it in multiple lines in < 2 minutes, so I might as well post my one-liner.

Shorter version:
new Array(100).fill(0).map((x,i)=>i+1).map(n=>((n%3?'':'fizz')+(n%5?'':'buzz'))||n).join(' ');

Tried to make it as compact as possible using no loops and no explicit if statements, and only using standard library functions to achieve looping.
>it is the year of lord 1024 + 512 + 256 + 128 + 64 + 32 + 1
>not relying on the compiler to solve all of your problems
godbolt.org/g/j46oU7
i-it's okay if the compiler optimized out my 100 integer statically allocated array r-right?

haha hi lol
here is my kode (lol)
pst.moe/paste/ozkgxy
xDDD
haha lol it is too long for post haha ;D

No Modulo/Division/Multiplication edition
for(let i = 1; i 0) {
if(++cf === 3) cf = 0;
if(++cb === 5) cb = 0;
}
if(!cf && !cb) console.log("fizzbuzz");
else if(!cf) console.log("fizz");
else if(!cb) console.log("buzz");
else console.log(i);
}

Don't need arithmetic to be Turing complete.

def fizz_buzz(lim)
for i in 1..lim
str = i % 3 == 0 ? i % 5 == 0 ? "FizzBuzz" : "Fizz" : i % 5 == 0 ? "Buzz" : ""
puts str.empty? ? i : str
end
end

fizz_buzz 100

Fuck I'm dumb...

Correction:

def fizz_buzz(lim)
for i in 1..lim
str = i % 3 == 0 ? i % 5 == 0 ? "FizzBuzz" : "Fizz" : i % 5 == 0 ? "Buzz" : i
puts str
end
end

fizz_buzz 20

Fuck sake, last one...

def fizz_buzz(lim)
for i in 1..lim
puts i % 3 == 0 ? i % 5 == 0 ? "FizzBuzz" : "Fizz" : i % 5 == 0 ? "Buzz" : i
end
end

fizz_buzz 100

running real-time on a gameboy emulator, no prerendered map

// Constant definitions

const PAIRS = [
{ word: 'Fizz', number: 3 },
{ word: 'Buzz', number: 5 }
];

const LIMIT = 100;

// Main loop

for (var n=1; n

program that does the following:
>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”.
and then submit in post box.

GO!

That's cool.

Now again, but this time is JSFuck

print("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\”.")

You missed that 'a' at the start, t1-san.

mapM_ fizzbuzz [1..100]
where
fizzbuzz :: Int -> IO ()
fizzbuzz x
| (mod x 3 == 0) && (mod x 5 == 0) = putStrLn "FizzBuzz"
| (mod x 5) == 0 = putStrLn "Buzz"
| (mod x 3) == 0 = putStrLn "Fizz"
| otherwise = putStrLn $ show x

DAMMIT

>needlessly making functions impure
main :: IO ()
main = mapM_ (putStrLn . fizzBuzz) [1..100]

fizzBuzz :: Int -> String
fizzBuzz n
| n `rem` 15 == 0 = "FizzBuzz"
| n `rem` 5 == 0 = "Buzz"
| n `rem` 3 == 0 = "Fizz"
| otherwise = show n

>doesn't even work right
kek'd