-
-
Save 17twenty/3019174 to your computer and use it in GitHub Desktop.
main(i){for(;i++<100;)printf(i%3?i%5?"%d\n":"Buzz\n":i%5?"Fizz\n":"FizzBuzz\n",i);} |
[nick@slimtop Development]$ gcc -std=c99 fizz_waffle.c -o fizz
fizz_waffle.c:1:1: warning: return type defaults to ‘int’ [enabled by default]
fizz_waffle.c: In function ‘main’:
fizz_waffle.c:1:1: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
fizz_waffle.c:1:31: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
That's a lot of warnings but yeah, it's good!. I was going to use the for-loop initial declaration but for some reason didn't want to have to stipulate c99. Nothing like losing to hubris :D
Even shorter now.
shaved 3 characters off it:
main(){for(int i=0;++i<101;)printf(printf("%s%s",i%3?"":"Fizz",i%5?"":"Buzz")?"\n":"%d\n",i);}
Cheers Dave, I've revised the gist!
Shaved 5 characters off it:
main(){for(int i=0;++i<101;)printf(i%3?i%5?"%d\n":"Buzz\n":i%5?"Fizz\n":"FizzBuzz\n",i);}
Shaved 10 characters off it:
main(i){for(i--;i++<100;)printf("%i%s%s\n",i,i%3?"\r":"\rfizz",i%5?"":"buzz");}
Shaved another 4 off that:
main(i){for(;i<101;puts(i++%5?"":"buzz"))printf("%i\r%s",i,i%3?"":"fizz");}
oh that is nice Gavin!
Shaved another 4 off that:
main(i){for(;i<101;puts(i++%5?"":"buzz"))printf("%i\r%s",i,i%3?"":"fizz");}
-1 bytes by changing printf()
main(i){for(;i<101;puts(i++%5?"":"Buzz"))printf(i%3?i%5?"%d":0:"Fizz",i);}
removing the stop condition brings it down to 69 bytes and is still technically fizzbuzz
main(i){for(;;puts(i++%5?"":"Buzz"))printf(i%3?i%5?"%d":0:"Fizz",i);}
This should be shorter...
main(){for(int i=1;i<101;++i){printf((printf("%s%s",(i%3==0)?"Fizz":"",(i%5==0)?"Buzz":""))?"\n":"%d\n",i);}}