"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”."
Use your language of choice - extra points for obscure ones.
In action. This assumes your object has a mutable slot named 'x' and prints into the terminal that runs Self VM.
Colton Scott
The "Fizz-Buzz test" is an interview question designed to help filter out the 99.5% of programming job candidates who can't seem to program their way out of a wet paper bag. The question is included in OP.
James Wood
Bumping with Bash.
#!/bin/bash
for i in {1..100}; do n=$( ((i%3==0)) && printf fizz )$( ((i%5==0)) && printf buzz ) [ -z "$n" ] && echo $i || echo $n done
Colton Turner
It's the end of all means in programming. In the end all of programming boils down into a fizzbuzz.
Isaiah Lewis
it's a Sup Forums meme and probably the only thing the 'programmers' here can code. welcome to Sup Forums, you'll see this thread multiple times a day. it's full of people circlejerking over the fact that they can write (or copy&paste) a simple program.
Bentley Adams
Less shaming, moar fizzbuzz.
Anthony Bennett
C in one line
for(int i = 1; i
Jaxson Ramirez
Ruby reporting in, is that obscure enough for you, OP?
# cheeky one-liner p (1..100).map{|i| (i%15).zero?? "FizzBuzz":(i%3).zero?? "Fizz":(i%5).zero?? "Buzz": i}
# "obscure edition": with distinct rows result = [] fizz = *(3..100).step(3) buzz = *(5..100).step(5) fizz_buzz = fizz & buzz
for i in range(1,101): print("FizzBuzz"[i*i%3*4:8--i**4%5] or i)
Cooper White
Even if the language isn't, the way it's done sure is.
Nolan Jackson
>bash kek
Luke Bell
What of it?
Jack Harris
So this may not be the sexiest code, but what it does is pretty interesting imo. During compile time, it automatically generates the code to do a naive implementation of fizzbuzz. As a result, the solution binary technically uses no loops. import std.stdio; import std.conv;
string fizzbuzz() { auto code = "auto fizzbuzz = \""; foreach (i; 1..101) { auto fizz = i % 3 == 0; auto buzz = i % 5 == 0; if (fizz && buzz) code ~= "fizzbuzz"; else if (fizz) code ~= "fizz"; else if (buzz) code ~= "buzz"; else code ~= to!string(i); code ~= "\n"; } code ~= "\";"; return code; }