[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

FizzBuzz obscure edition

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 23
Thread images: 3

File: 1467699667056.jpg (12KB, 362x270px) Image search: [Google]
1467699667056.jpg
12KB, 362x270px
Alright /g/, FizzBuzz time!

"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.

To start it off I give you Self.

x: 0.
[x < 100] whileTrue: [
x: x + 1.
((x % 3) = 0) ifTrue: ['Fizz' print].
((x % 5) = 0) ifTrue: ['Buzz' print].
(((x % 3) != 0) && ((x % 5) != 0)) ifTrue: [x print].
'\n' print.
]
>>
What is "fizzbuzz"?
>>
>>55966867
In action. This assumes your object has a mutable slot named 'x' and prints into the terminal that runs Self VM.
>>
>>55966922
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.
>>
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
>>
>>55966922
It's the end of all means in programming. In the end all of programming boils down into a fizzbuzz.
>>
>>55966922
it's a /g/ meme and probably the only thing the 'programmers' here can code. welcome to /g/, 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.
>>
>>55967202
Less shaming, moar fizzbuzz.
>>
C in one line

for(int i = 1; i <= 100; ++i) printf( !(i % 15) ? "fizzbuzz\n" : !(i % 3) ? "fizz\n" : !(i % 5) ? "buzz\n" : "%i\n", i);
>>
>>55966867

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

rest = Array(1..100) - fizz - buzz
fizz -= fizz_buzz
buzz -= fizz_buzz

f,b,fb,r = fizz.shift, buzz.shift, fizz_buzz.shift, rest.shift

until fizz.empty? and buzz.empty? and fizz_buzz.empty? and rest.empty?
case [f,b,fb,r].compact.min
when f then result << "Fizz"; f = fizz.shift
when b then result << "Buzz"; b = buzz.shift
when fb then result << "FizzBuzz"; fb = fizz_buzz.shift
else result << r; r = rest.shift
end
end

p result
>>
 for (i in 1:100) {
print(
paste(rep("Fizz",((is.finite(sum(i%%3, 1/(i%%3), na.rm=TRUE) %% 1) == FALSE) * 1)),
rep("Buzz",((is.finite(sum(i%%5, 1/(i%%5), na.rm=TRUE) %% 1) == FALSE) * 1)),
rep(i,(((is.finite(sum(i%%3, 1/(i%%3), na.rm=TRUE) %% 1) == TRUE) &
(is.finite(sum(i%%5, 1/(i%%5), na.rm=TRUE) %% 1) == TRUE)) * 1)),
collapse='', sep=""),quote=FALSE)
}

Deliberately odd.
>>
>>55966867

Madatory:

for i in range(1,101):
print("FizzBuzz"[i*i%3*4:8--i**4%5] or i)
>>
>>55968870
Even if the language isn't, the way it's done sure is.
>>
>>55967071
>bash
kek
>>
>>55969497
What of it?
>>
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;
}

void main()
{
mixin(fizzbuzz());
writeln(fizzbuzz);
}
>>
public void fizzBuzz(){
for(int i=1; i<=100; i++){
if(i % 3 == 0)
System.out.print("Fizz");

if(i % 5 == 0)
System.out.print("Buzz");

if(i % 3 != 0 && i % 5 != 0)
System.out.print(i);

System.out.println("");
}
}
>>
>>55969609
Or rather, it generates the solution to fizzbuzz as a string during compile time, and the executable only prints the string.
>>
>>55969626
Wrote this on my phone, it's just the method.
>>
>>55966867
An elegant solution written in an elegant language:

for ((n=0; n<100; n+=15)); do
echo $((n+1))
echo $((n+2))
echo $((n+3)) Fizz
echo $((n+4))
echo $((n+5)) Buzz
echo $((n+6)) Fizz
echo $((n+7))
echo $((n+8))
echo $((n+9)) Fizz
echo $((n+10)) Buzz
if ((n+10 == 100)); then break; fi
echo $((n+11))
echo $((n+12)) Fizz
echo $((n+13))
echo $((n+14))
echo $((n+15)) Fizz Buzz
done
>>
File: ghetto_modulo.webm (1MB, 1532x716px) Image search: [Google]
ghetto_modulo.webm
1MB, 1532x716px
>>55966867
>>
>>55969701
kek this wins.
>>
>>55969534
nothing senpai :^)
Thread posts: 23
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.