[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

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: 42
Thread images: 8

File: fizzbuzz.jpg (12KB, 362x270px) Image search: [Google]
fizzbuzz.jpg
12KB, 362x270px
ITT we come up with the meme-iest implementation possible.

I'll start:

for i in range(1,101): print "FizzBuzz"[i*i%3*4:8--i**4%5] or i
>>
>>57167014
>++++++[<++++++++>-]++++++++++[>++++++++++<-]>[>>+<<->>>>+++<<[>+>->+<
[>]>[<+>-]<<[<]>-]>[-<+>]>>>[-]+>[-]<<[>-<[>>+<<-]]>>[<<+>>-]<[>++++++
+[>++++++++++<-]>.>>+++[>+++++<-]>[<+++++++>-]<.>++++[>++++<-]>+[<<+>>
-]<<..[-]<<[-]<<-<<<<<<<+>>>>>>>]<[-]<[-]+++++<<[>+>->+<[>]>[<+>-]<<[<
]>-]>[-<+>]>+>>[-]+>[-]<<[>-<[>>+<<-]]>>[<<+>>-]<[>++++++[>+++++++++++
<-]>.>+++++++++[>+++++++++++++<-]>.+++++..[-]<<[-]<<-<<<<<<<+>>>>>>>]<
[-]<[-]>[-]<<<<<<[>>>>>+>+<<<<<<-]>>>>>[<<<<<+>>>>>-]+>[<<<<<<[-]>>>>>
->[-]]<[<<[>>>+>+<<<<-]>>>[-<<<+>>>]>>>++++++++++<<[->+>-[>+>>]>[+[-<+
>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]>>[
>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++++++<]>.[-]]<<++
++++[-<++++++++>]<.[-]<<[-<+>]<-<<-]++++++++++.[-]<<<<]
>>
print("1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n16\n17\nFizz\n19\nBuzz\nFizz\n22\n23\nFizz\nBuzz\n26\nFizz\n28\n29\nFizzBuzz\n31\n32\nFizz\n34\nBuzz\nFizz\n37\n38\nFizz\nBuzz\n41\nFizz\n43\n44\nFizzBuzz\n46\n47\nFizz\n49\nBuzz\nFizz")
>>
>>57167047
I want it to be something I can remember in case I ever get asked in an interview
>>
#include<stdio.h>

int main(void){
FILE *out = fopen("fizzbuzz.c","w");
fprintf(out,"#include<stdio.h>\n\nint main(void){\n\tfor(int i = 0;i<100;i++){\n\tif(i%%15 == 0)\n\t\tprintf(\"fizzbuzz\\n\");\n\telse if(i%%5 == 0)\n\t\tprintf(\"fizz\\n\");\n\telse if(i%%3 == 0)\n\t\tprintf(\"buzz\\n\");\n\telse\n\t\tprintf(\"%%d\\n\",i);\n\t}\n\treturn 0;\n}");
fclose(out);
system("cc fizzbuzz.c -o fizzbuzz");
system("./fizzbuzz");
return 0;
}

took me a bit
>>
>>57167255
I’m sure it would make quite an impression if someday they ask you to and you manage to write it without hesitating like this

and with enough training, I think it can be done, I mean, it’s “only” 756 characters
>>
>>57167348
I improved it with commandline arguments
#include<stdio.h>
#include<stdlib.h>

int main(int argc, char** argv){
int length;
if(argc > 1){
length = atoi(argv[1]);
}else{
length = 100;
}
FILE *out = fopen("fizzbuzz.c","w");
fprintf(out,"#include<stdio.h>\n\nint main(void){\n\tfor(int i = 0;i<%d;i++){\n\tif(i%%15 == 0)\n\t\tprintf(\"fizzbuzz\\n\");\n\telse if(i%%5 == 0)\n\t\tprintf(\"fizz\\n\");\n\telse if(i%%3 == 0)\n\t\tprintf(\"buzz\\n\");\n\telse\n\t\tprintf(\"%%d\\n\",i);\n\t}\n\treturn 0;\n}",length);
fclose(out);
system("cc fizzbuzz.c -o fizzbuzz");
system("./fizzbuzz");
return 0;
}
>>
This is the proper way to code FizzBuzz

https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

Even the code of conduct is a meme.
>>
>>57167417
isnt that the default CoC for all github shit
>>
>>57167473
No, you can make your own contributing file.
>>

#include <iostream>

using namespace std;

int main()
{
for (int iCont = 1; iCont <= 100; iCont++) {
if (iCont % 15 == 0) cout << "FizzBuzz" << endl;
else if (iCont % 3 == 0) cout << "Fizz" << endl;
else if (iCont % 5 == 0) cout << "Buzz" << endl;
else cout << iCont << endl;
}
}

>>
>>
>>57168747
that's not even a meme response, that's what you do if you don't want to get hired
>>
Javascript because I am a faggot

var t=0;
for(i=1;i<101;i++){(i%3==0)?((i%5==0)?t='fizzbuzz':t='buzz'):((i%5==0)?t='fizz':t=i);console.log(t);}
>>
>>57168788
it's very readable, that's a plus for many
>>
#include <stdio.h>

int main()
{
FILE *f = fopen(".fb", "w");
char str[8];
int i;

for (i = 1; i < 101; ++i)
{
sprintf(str, "%i", i);
fputs(!(i % 3) ? "Fizz" : "", f);
fputs(!(i % 5) ? "Buzz" : "", f);
fputs((i % 3 && i % 5) ? str : "", f);
fputc('\n', f);
}

fclose(f);
system("cat .fb && rm .fb && echo ':^)'");

return 0;
}
>>
>>57168747
I'm too bad at programming to do it any other way than this
>>
No modulo, no division:

let rec cycle ls = seq { yield! ls; yield! cycle ls }
let fizzes = cycle [""; ""; "Fizz"]
let buzzes = cycle [""; ""; ""; ""; "Buzz"]

Seq.take 100 >> Seq.mapi (fun i (x, y) ->
match x+y with "" -> string (i+1) | _ -> x+y)
<| Seq.zip fizzes buzzes
|> Seq.iter (printfn "%s\n")
>>
#include <stdio.h>

/* Lookup table for efficiency */
const char * const LIST[] =
{
"1", "2", "Fizz", "4",
"Buzz", "Fizz", "7", "8",
"Fizz", "Buzz", "11", "Fizz",
"13", "14", "Fizzbuzz", "16",
"17", "Fizz", "19", "Buzz",
"Fizz", "22", "23", "Fizz",
"Buzz", "26", "Fizz", "28",
"29", "Fizzbuzz", "31", "32",
"Fizz", "34", "Buzz", "Fizz",
"37", "38", "Fizz", "Buzz",
"41", "Fizz", "43", "44",
"Fizzbuzz", "46", "47", "Fizz",
"49", "Buzz", "Fizz", "52",
"53", "Fizz", "Buzz", "56",
"Fizz", "58", "59", "Fizzbuzz",
"61", "62", "Fizz", "64",
"Buzz", "Fizz", "67", "68",
"Fizz", "Buzz", "71", "Fizz",
"73", "74", "Fizzbuzz", "76",
"77", "Fizz", "79", "Buzz",
"Fizz", "82", "83", "Fizz",
"Buzz", "86", "Fizz", "88",
"89", "Fizzbuzz", "91", "92",
"Fizz", "94", "Buzz", "Fizz",
"97", "98", "Fizz", "Buzz",
};

int main()
{
int i;

for (i = 0; i < 100; ++i)
puts(LIST[i]);

return 0;
}
>>
i = 1

while i < 101:
if i % 15 == 0:
print("FizzBuzz")
elif i % 5 == 0:
print("Buzz")
elif i % 3 == 0:
print("Fizz")
else:
print(i)
i = i + 1


Why would you do it any other way that the simplest/most readable way?

Is there a simpler/more readable way?
>>
Look ma, no if statements
f = dict(zip(range(1,101), range(1,101)))
a = dict.fromkeys(list(filter(lambda n: n % 3 == 0, range(1, 101))), "fizz")
b = dict.fromkeys(list(filter(lambda n: n % 5 == 0, range(1, 101))), "buzz")
c = dict.fromkeys(list(filter(lambda n: (n % 15 == 0), range(1, 101))), "fizzbuzz")
d = {**a, **b, **c}

for key in d:
f[key] = d[key]

for key in f:
print(f[key])
>>
>>57167417

kek'd
>>
File: ghetto_modulo.webm (1MB, 1532x716px) Image search: [Google]
ghetto_modulo.webm
1MB, 1532x716px
>>57167014
>>
How about one that relies on a procedure: FB where FB(n) returns n 8/15ths of the time, 'fizz' 4/15ths of the time, 'buzz' 2/15ths of the time and 'fizzbuzz' 1/15th of the time?
>>
>>57168770
slightly verbose but those code seems fine
>>
#include <stdio.h>

int main()
{
int a, b;
int i = 0;

begin:
if (++i == 101) goto end;
a = 15;
goto test;
test5:
a = 5;
goto test;
test3:
a = 3;
goto test;
test:
b = 0;
testinc:
b += a;
if (b < i) goto testinc;
if (b != i) goto fail;
puts((a == 15) ? "Fizzbuzz" : (a == 5) ? "Buzz" : "Fizz");
goto begin;
fail:
if (a == 15) goto test5; if (a == 5) goto test3;
printf("%i\n", i);
goto begin;
end:
return 0;
}
>>
>>57168814
Use normal if statements not shorthand ones faggot.
>>
>>57168814
>that long solution
step it up
for(i=1;i<=99;i++)console.log(((i%3?"":"Fizz")+(i%5?"":"Buzz"))||i)
>>
>>57167014

 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)


I'm a newfag that just started learning python so I'm still shit at it, but I thought I might make a retarded mistake that could make someone laugh.
>>
>>57170974
first if can be x % 15
>>
Easy.
#include <stdio.h>
main ()
{
int num = 1;

printf("Fizz Buzz. Press 'n' to exit, press any other key to start.\n");

while((getchar()!='n') && (getchar()!='N'))
//If user presses 'n', while loop stops
//Gets user input every time it loops
{
printf("\n\n%d\n", num);
num = num + 1;
printf("%d\n", num);
num = num + 1;
printf("fizz\n");
num = num + 1;
printf("%d\n", num);
num = num + 1;
printf("buzz\n");
num = num + 1;
printf("fizz\n");
num = num + 1;
printf("%d\n", num);
num = num + 1;
printf("%d\n", num);
num = num + 1;
printf("fizz\n");
num = num + 1;
printf("buzz\n");
num = num + 1;
printf("%d\n", num);
num = num + 1;
printf("fizz\n");
num = num + 1;
printf("%d\n", num);
num = num + 1;
printf("%d\n", num);
num = num + 1;
printf("fizzbuzz\n");
num = num + 1;
printf("%d\n", num);
num = num + 1;
printf("%d\n", num);
num = num + 1;
printf("fizz\n");
num = num + 1;
printf("%d\n", num);
num = num + 1;
printf("buzz\n");
num = num + 1;
printf("fizz\n");
num = num + 1;
printf("%d\n", num);
num = num + 1;
printf("%d\n", num);
num = num + 1;
printf("fizz\n");
num = num + 1;
printf("buzz\n");
num = num + 1;
printf("%d\n", num);
num = num + 1;
printf("fizz\n");
num = num + 1;
printf("%d\n", num);
num = num + 1;
printf("%d\n", num);
num = num + 1;
printf("fizzbuzz\n");
num = num + 1;

printf("Continue?\n");
printf("y/n\n");

};
return 0;
};
>>
File: look_at_my_slippers.png (6KB, 204x319px) Image search: [Google]
look_at_my_slippers.png
6KB, 204x319px
>>57167076
hired
>>
rate my scalable and modular FizzBuzz implementation in C++:
#include <type_traits>
#include <limits>
#include <iterator>
#include <algorithm>
#include <string>
#include <iostream>

template< typename T >
using integral_iterator_base_t = std::enable_if_t< std::numeric_limits< T >::is_integer, std::iterator< std::random_access_iterator_tag, T, std::ptrdiff_t, T, T > >;
template< typename T >
class integral_iterator_t : public integral_iterator_base_t< T >
{
using base_t = integral_iterator_base_t<T>;
typename base_t::value_type m_value;

public:
integral_iterator_t() = default;
integral_iterator_t( decltype( m_value ) const& value ) : m_value{ value } {}
operator auto const& () const { return m_value; }
operator auto& () { return m_value; }
typename base_t::reference operator* () const { return *this; }
};

int main()
{
using uint_iterator_t = integral_iterator_t< unsigned >;
std::transform( uint_iterator_t{ 1 }, uint_iterator_t{ 35 }, std::ostream_iterator< std::string >{ std::cout, ", " },
[]( auto const& value )
{
static std::string lut[] = { {}, "Fizz", "Buzz", lut[ 1 ] + lut[ 2 ] };
lut[ 0 ] = std::to_string( value );
return lut[ !( value % 3 ) + ( !( value % 5 ) << 1) ];
} );
}
>>
def generate(range = 1..100, factors = [[3, 'Fizz'], [5, 'Buzz']])
code = []
code << "(#{range}).each do |i|"
code << " case"
factors.powerset.reverse.each do |arr|
n = arr.map(&:first).reduce(&:*)
str = arr.map(&:second).reduce(&:+)
code << " when i.modulo(#{n}).zero?"
code << " puts '#{str}'"
end
code << " else"
code << " puts i"
code << " end"
code << "end"
code.join("\n")
end

class Array
def powerset
1.upto(size).flat_map{ |k| combination(k).to_a }
end

def second
self[1]
end
end

eval(generate)

>>
File: pdf.png (25KB, 616x877px) Image search: [Google]
pdf.png
25KB, 616x877px
DOCLAY FizzBuzz:

REGISTER i ARABIC 1 1;
REGISTER mod3 ARABIC 1 1;
REGISTER mod5 ARABIC 1 1;

DEFAULTS
SET
WHILE = "${i} <= 100",
IF = "${mod3} = 3 && ${mod5} = 5",
MAKENODE = "LAST, <line>Fizzbuzz</line>",
REGRESET = "mod3 = 0",
REGRESET = "mod5 = 0",
ELSE, IF = "${mod3} = 3",
MAKENODE = "LAST, <line>Fizz</line>",
REGRESET = "mod3 = 0",
ELSE, IF = "${mod5} = 5",
MAKENODE = "LAST, <line>Buzz</line>",
REGRESET = "mod5 = 0",
ELSE,
MAKENODE = "LAST, <line>${i}</line>",
ENDIF,
ENDIF,
ENDIF,
REGINC = i,
REGINC = mod3,
REGINC = mod5,
ENDWHILE,
FONT = "Courier";

LAYOUT P4Page:
BODY body (10mm, 10mm, 215mm * 280mm);
EOLAY

EODOCLAY
>>
File: images.jpg (5KB, 275x183px) Image search: [Google]
images.jpg
5KB, 275x183px
>>57167014
/*
FizzBuzzBlink for Arduino
Turns on LEDs on for one second, then off for one second, repeatedly according to FizzBuzz status.

This example code is NOT in the public domain. DO NOT STEAL THIS.
*/

int fizzLed = 13;
int buzzLed = 12;

void setup() {
pinMode(fizzLed, OUTPUT);
pinMode(buzzLed, OUTPUT);
}

void loop() {
for(int a=1; a<=100; a++)
{
//Turn both LEDs off
digitalWrite(fizzLed,LOW);
digitalWrite(buzzLed,LOW);

//Wait one second with the lights off
delay(1000);

//It's a fizz
if(a%3)
digitalWrite(fizzLed,HIGH);

//It's a buzz
if(a%5)
digitalWrite(buzzLed,HIGH);

//Leave them on for one second
delay(1000);
}
}
>>
File: fizzbuzz.png (11KB, 335x325px) Image search: [Google]
fizzbuzz.png
11KB, 335x325px
FizzBuzz for GameBoy

GB File:
https://drive.google.com/file/d/0B2YI91EWUu1AWTl2c05kM3pJaWc/view?usp=sharing

ASM file:
https://drive.google.com/file/d/0B2YI91EWUu1AWWFrTWFDQTdkd1E/view?usp=sharing
>>
FizzBuzz for clusters


#include <stdio.h>
#include <string.h>
#include <mpi.h>

int main(int argc, char **argv ){
int id,comsize;
char output[101*9];

MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&id);
MPI_Comm_size(MPI_COMM_WORLD,&comsize);

float range = 100.0f/(float)comsize;
int start = (int)(range*(float)id+1);
int end = (int)(range*((float)id+1));
char buf[(int)(range*9)+1];

int i,j;
for (i=start,j=0;i<=end;++i,++j){
if (i%3==0 && i%5==0) strcpy(&buf[j*9],"FizzBuzz\n");
else if (i%3==0) strcpy(&buf[j*9],"Fizz\n");
else if (i%5==0) strcpy(&buf[j*9],"Buzz\n");
else sprintf(&buf[j*9],"%d\n",i);
}

MPI_Gather(&buf,(int)(range*9),MPI_CHAR,&output,(int)(range*9),MPI_CHAR,0,MPI_COMM_WORLD);

if (id==0){
for (i=0;i<100;++i)
printf("%s",&output[i*9]);
}

MPI_Finalize();

return 0;
}
>>
File: AWW.jpg (362KB, 2388x1470px) Image search: [Google]
AWW.jpg
362KB, 2388x1470px
     for (int i = 1; i <= 100; i++)
{
switch i
{
case 1: cout << endl << i;
break;
case 2: cout << endl << i;
break;
case 3: cout << endl << "fizz";
break;
case 4: cout << endl << i;
break;
case 5: cout << endl << "buzz";
break;
case 6: cout << endl << "fizz";
break;
case 7: cout << endl << i;
break;
case 8: cout << endl << i;
break;
case 9: cout << endl << "fizz";
break;
case 10: cout << endl << "buzz";
break;
case 11: cout << endl << i;
break;
case 12: cout << endl << "fizz";
break;
case 13: cout << endl << i;
break;
case 14: cout << endl << i;
break;
case 15: cout << endl << "fizzbuzz";
break;
case 16: cout << endl << i;
break;
case 17: cout << endl << i;
break;
case 18: cout << endl << "fizz";
break;
case 19: cout << endl << i;
break;
case 20: cout << endl << "buzz";
break;
case 21: cout << endl << "fizz";
break;
case 22: cout << endl << i;
break;
case 23: cout << endl << i;
break;
case 24: cout << endl << "fizz";
break;
case 25: cout << endl << "buzz";
break;
case 26: cout << endl << i;
break;
case 27: cout << endl << "fizz";
break;
case 28: cout << endl << i;
break;
case 29: cout << endl << i;
break;
case 30: cout << endl << "fizzbuzz";
break;
case 31: cout << endl << i;
break;
case 32: cout << endl << i;
break;
case 33: cout << endl << "fizz";
break;
case 34: cout << endl << i;
break;
case 35: cout << endl << "buzz";
break;
case 36: cout << endl << "fizz";
break;
case 37: cout << endl << i;
break;
case 38: cout << endl << i;
break;
case 39: cout << endl << "fizz";
break;
case 40: cout << endl << "buzz";
break;
}
}
>>
/*
FizzBuzzBlinker for Arduino
Turns on LEDs on for one second, then off for one second, repeatedly according to FizzBuzz status.

This example code is protected under the GNU General Public License 3
*/

int fizzLed = 13;
int buzzLed = 12;

void setup() {
pinMode(fizzLed, OUTPUT);
pinMode(buzzLed, OUTPUT);
}

void loop() {
for(int a=1; a<=100; a++)
{
//Turn both LEDs off
digitalWrite(fizzLed,LOW);
digitalWrite(buzzLed,LOW);

//Wait one second with the lights off
delay(1000);

//It's a fizz
if(a%3)
digitalWrite(fizzLed,HIGH);

//It's a buzz
if(a%5)
digitalWrite(buzzLed,HIGH);

//Leave them on for one second
delay(1000);
}
}
>>
>>57175005

literally why would this be under the GPL v3 that makes like no sense who the fuck thought of this

who applies a license to fizzbuzz
>>
>>57175029
see >>57173716
Thread posts: 42
Thread images: 8


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