@echo off setlocal rem ケータイからカキコ rem 動くか知らん :START set count=1 if count%15==0 ( echo FizzBuzz set printflag=true ) if count%5==0 ( echo Buzz set printflag=true ) if count%3==0 ( echo Fizz set printflag=true ) if not "%printflag%"=="" echo %count% set /a count+=1 if %count% gtr 100 ( goto :END ) else ( goto :START ) :END pause exit
String fizz = "Fizz"; String buzz = "Buzz"; StringBuffer ret = new StringBuffer(); for (int i = 1; i < 101; i++) { if ((i % 3) == 0) { ret.append(fizz); } if ((i % 5) == 0) { ret.append(buzz); } if (ret.length() == 0) { System.out.println(i); } else { System.out.println(ret.toString()); ret = new StringBuffer(); } }
32 :08/05/02
/* 普通のコードしか思いつかねぇ */ #include <stdio.h> int main(void) { int i; for (i = 1; i <= 100; i++) { if (i % 3 == 0 && i % 5 ==0) printf("FizzBuzz\n"); else if (i % 3 == 0) printf("Fizz\n"); else if (i % 5 == 0) printf("Buzz\n"); else printf("%d\n", i); } return (0); }
33 :08/05/02
/* じゃあ、あまり普通じゃないコードを */ #include <stdio.h> const char *s[] = { "FizzBuzz\n", "%d\n", "%d\n", "Fizz\n", "%d\n", "Buzz\n", "Fizz\n", "%d\n", "%d\n", "Fizz\n", "Buzz\n", "%d\n", "Fizz\n", "%d\n", "%d\n" }; int main() { int i; for (i = 1; i <= 100; i++) { printf(s[i % 15], i); } }
34 :08/05/02
REM FizzBuzz.bat @ECHO OFF SETLOCAL SET Rest=0 SET Start=1 SET End=100 SET Count=%Start% :BEGIN SET FizzBuzz= CALL :CALC %Count% 3 Fizz CALL :CALC %Count% 5 Buzz CALL :CALC %Count% 15 FizzBuzz IF "%FizzBuzz%"=="" ( ECHO %Count% ) ELSE ( ECHO %FizzBuzz% ) SET /A Count+=1 IF %Count% GTR %End% ( GOTO :FINISH ) ELSE ( GOTO :BEGIN ) :FINISH PAUSE EXIT :CALC SET /A "Rest=%1 %% %2" IF %Rest%==0 SET FizzBuzz=%3 GOTO :EOF
// Fizz public class FizzBuzz { public static void main(String[] args) {
for (int i = 1; i <= 100; i++) {
System.out.println( i % 15 == 0 ? "FizzBuzz" : i % 5 == 0 ? "Buzz" : i % 3 == 0 ? "Fizz" : i); } } }
43 :08/05/02
#include<stdio.h> int main(int,char**) { int i = 0; while( ++i <= 100 ) printf((i%15) ? "FizzBuzz\n" : ((i%3) ? "Fizz\n" : ((i%5) ? "Buzz\n" : "%d\n") ) , i ); return 0; }
44 :08/05/02
逆だw #include<stdio.h> int main(int,char**) { int i = 0; while( ++i <= 100 ) printf( (i%15) ? ( (i%3) ? ( (i%5) ? "%d\n" : "Fizz\n") : "Buzz\n" ) : "FizzBuzz\n" , i ); return 0; }
45 :08/05/02
#include <stdio.h> int main() { printf("#include <stdio.h>\n\n"); printf("int main()\n"); printf("{\n"); int i; for (i = 1; i <= 100; i++) { if (i % 15 == 0) puts("\tputs(\"FizzBuzz\");"); else if (i % 3 == 0) puts("\tputs(\"Fizz\");"); else if (i % 5 == 0) puts("\tputs(\"Buzz\");"); else printf("\tputs(\"%d\");\n", i); } printf("\treturn 0;\n"); printf("}\n"); return 0; }
10 FOR L=1 TO 100 20 D=0 30 IF L MOD 3=0 THEN PRINT "FIZZ"; : D=1 40 IF L MOD 5=0 THEN PRINT "BUZZ"; : D=1 50 IF D=1 THEN PRINT "" : GOTO 70 60 PRINT L 70 NEXT L
61 :08/05/06
10 C3=0: C5=0 20 FOR L=1 TO 100 30 C3=C3+1+3*(C3=2) : C5=C5+1+5*(C5=4) 40 IF C3=0 THEN PRINT "FIZZ"; 50 IF C5=0 THEN PRINT "BUZZ"; 60 IF C3*C5=0 THEN PRINT "" ELSE PRINT L 70 NEXT L
# そんじゃ、pythonで for i in range(1, 101): if i % 3 == 0 and i % 5 == 0: print 'FizzBuzz' elif i % 3 == 0: print 'Fizz' elif i % 5 == 0: print 'Buzz' else: print i
84 :08/05/06
# rubyで for i in 1..100 if i % 3 == 0 && i % 5 == 0 print("FizzBuzz\n") elsif i % 3 == 0 print("Fizz\n") elsif i % 5 == 0 print("Buzz\n") else print(i, "\n") end end
85 :08/05/07
void fizzbuzz(int num) { if (num) { fizzbuzz(num-1); switch( (((num % 5) == 0) << 1) | ((num % 3) == 0) ) { case 0: printf("%d\n", num); break; case 1: printf("fizz\n"); break; case 2: printf("buzz\n"); break; case 3: printf("fizzbuzz\n"); break; } } } void main() { fizzbuzz(100); }
86 :08/05/07
#include <stdio.h> int main(int argc,int argv) { for (argc=1;argc<=100;argc++) { switch(argv=argc%15) { case 0: case 3: case 6: case 9: case 12: printf("Fizz"); if (argv) break; case 5: case 10: printf("Buzz"); break; default: printf("%d",argc); break; } printf("¥n"); } return (0); }
let rec fizzbuzz n = let num = string_of_int n in let fizz = if (n mod 3 = 0) then "Fizz" else "" in let buzz = if (n mod 5 = 0) then "Buzz" else "" in match n with 101-> () |_-> if (n mod 3 <> 0 ) then if (n mod 5 <> 0) then print_string num; print_string fizz; print_string buzz; print_string "\n"; fizzbuzz (n+1) in fizzbuzz 1