Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

fizzbuzz

Name: Anonymous 2011-03-25 23:20

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

Language: C
Difficulty: One line of code (i.e. one semicolon).

Shortest program wins.

Name: Anonymous 2011-03-26 0:03

inb4 Golfscript

Name: Anonymous 2011-03-26 0:09

#include <stdio.h>
int main(void) { for(int i = 0;i++<100;!(i%3)?!(i%5)?printf("fizzbuzz\n"):printf("fizz\n"):!(i%5)?printf("buzz\n"):printf("%d\n",i));}

Name: Anonymous 2011-03-26 0:56

Longest program wins.

inb4 Java

Name: Anonymous 2011-03-26 1:43

If I add "1\n2\nfizz\n4\nbuzz\nfizz\n7\n8\nfizz\nbuzz\n11\nfizz\n13\n..." to the string table, does that count against my code size?

Name: Anonymous 2011-03-26 2:41

Shortest program wins.
Here's my winning entry, in Perl of course:

Name: Anonymous 2011-03-26 3:21

According to http://golf.shinh.org/p.rb?FizzBuzz#C the record is 73 characters (with "main(){}", but without headers or the 1 line limit)

here's a tester thingee: http://golf.shinh.org/checker.html

Name: Anonymous 2011-03-26 3:50

>>7

ffffffuuuuuuuuuu, can't get below 102.

main(){int x=0;for(;++x-101;)x%5?x%3?printf("%d\n",x):puts("fizz"):x%3?puts("buzz"):puts("fizzbuzz");}

still shorter than >>3

Name: Anonymous 2011-03-26 7:29

>>8 You can merge calls to printing

main(){int x=0;for(;++x-101;)x%5?x%3?printf("%d\n",x):puts("fizz"):puts(x%3?"buzz":"fizzbuzz");}

main(){int x=0;for(;++x-101;)x%5?printf(x%3?"%d\n":"fizz\n",x):puts(x%3?"buzz":"fizzbuzz");}

Name: Anonymous 2011-03-26 7:32


>>9
of course one can go deeper

//7
main(){int x=0;for(;++x-101;)x%5?x%3?printf("%d\n",x):puts("fizz"):x%3?puts("buzz"):puts("fizzbuzz");}
//8
main(){int x=0;for(;++x-101;)x%5?x%3?printf("%d\n",x):puts("fizz"):puts(x%3?"buzz":"fizzbuzz");}
main(){int x=0;for(;++x-101;)x%5?printf(x%3?"%d\n":"fizz\n",x):puts(x%3?"buzz":"fizzbuzz");}
// new version
main(){int x=0;for(;++x-101;)printf(x%5?x%3?"%d\n":"fizz\n":x%3?"buzz\n":"fizzbuzz\n",x);}

Name: Anonymous 2011-03-26 7:36

>>10 I messed up quotes by one.

Also using argc instead of variable declaration we can write even shorter vesrion.


//10
main(){int x=0;for(;++x-101;)printf(x%5?x%3?"%d\n":"fizz\n":x%3?"buzz\n":"fizzbuzz\n",x);}
//new
main(x){for(x=0;++x-101;)printf(x%5?x%3?"%d\n":"fizz\n":x%3?"buzz\n":"fizzbuzz\n",x);}

Name: Anonymous 2011-03-26 8:45

>>11
still 86 characters.  u suk.

Name: Anonymous 2011-03-26 9:01

#include <fizzbuzz.h>
void main() { fizzbuzz(); }


FLAWLESS VICTORY

Name: Anonymous 2011-03-26 9:25

>>13
HAXED ANUS

Name: Anonymous 2011-03-26 10:27

>>13
void fizzbuzz();main(){fizzbuzz();}

Name: Anonymous 2011-03-26 11:36

nate higgers

Name: Anonymous 2011-03-26 11:49

we've had this thread at least twice before

Name: Anonymous 2011-03-27 2:38

//>>11 sucks
main(i){for(;i<101;puts(i++%5?"":"Buzz"))printf(i%3?i%5?"%d":"":"Fizz",i);}

Don't change these.
Name: Email:
Entire Thread Thread List