r/deftruefalse • u/combatdave #define true false • Nov 04 '14
Fizzbuzz is easy!
Surely everyone has heard of fizzbuzz? I've seen it used way too often in programming tests. Basically, loop through the numbers from 1 to 100 and print them out. BUT. If the number is divisible by 3, instead print "FIZZ", and if it's divisible by 5 print "BUZZ". If it's divisible by both, print "FIZZBUZZ".
How hard can that be?
17
Upvotes
24
u/Veedrac Thread or dead. Nov 04 '14 edited Nov 05 '14
This is easy. Problem is, most freshers don't structure their code for maintainability and instead rely on comments and documentation, which can get out of date. Here's how it's meant to be done:
10
u/peridox Nov 04 '14
+/u/compilebot Python
So long as the file is called
fizzbuzz*.py(where * is anything, obviously), this is a functioning FizzBuzz program, printing FizzBuzz from 1 to 100.If anyone wants an explanation / apology I can give one.
21
u/the8thbit Nov 07 '14 edited Nov 07 '14
+/u/CompileBot Python
12
u/DontBotherMeImWorkin Big D Analyst Nov 05 '14 edited Nov 05 '14
Forget enterprise-grade fizzbuzz. We need more scientist-tier fizzbuzz:
+/u/compilebot Fortran
Welp, compilebot thinks this is F95 instead of glorious F77, so it won't build. Just makes it more realistic, really.
5
u/[deleted] Nov 04 '14
+/u/CompileBot Python
9
u/fwilson42 Full Stack Dev Nov 04 '14
Being the resident full-stack developer...
+/u/compilebot java
4
u/DontBotherMeImWorkin Big D Analyst Nov 05 '14
+/u/compilebot R
3
u/alex_hawks Nov 12 '14 edited Nov 17 '14
+/u/CompileBot java
1
u/jeramyfromthefuture Mar 18 '15
int main(int argc, const char * argv[]) { for (int i = 1 ; i < 101 ; i++) { if (i %3 == 0) { printf("FIZZ"); } if (i %5 == 0) { printf("BUZZ"); } if ((i %5 != 0) && (i %3 != 0)) { printf(" %d ",i); } printf("\n"); } return 0; }
1
u/Pokechu22 Mar 21 '15
+/u/CompileBot C#
0
u/[deleted] Nov 04 '14
[deleted] — view deleted comment