Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualCornstalks

Posted 07 July 2013 - 12:24 AM

C99, 365 characters including whitespace (newlines and all), 314 excluding whitespace (I personally think we should be counting whitespace):
#define T ".\nTake one down and pass it around, "
#define B " bottles of beer"
#define b "1 bottle of beer"
#define W B" on the wall"
#define w b" on the wall"
int main(){for(int j=100;j--;)printf(j?j>1?"%d"W", %d"B:w", "b:"No more"W", no more"B,j,j),printf(j?j>1?j>2?T"%d"W".\n\n":T w".\n\n":T"no more"W".\n\n":".\nGo to the store and buy some more, 99"W".",j-1);}
I'm tired. It's time for bed. I might try some more tomorrow.

Edit: I just learned implicit function declaration was made illegal in C99, so my code is an unholy union of C89 and C99. Here's a C89 version (added 10 characters):
#define T ".\nTake one down and pass it around, "
#define B " bottles of beer"
#define b "1 bottle of beer"
#define W B" on the wall"
#define w b" on the wall"
int main(){for(int j=100;j--;)printf(j?j>1?"%d"W", %d"B:w", "b:"No more"W", no more"B,j,j),printf(j?j>1?j>2?T"%d"W".\n\n":T w".\n\n":T"no more"W".\n\n":".\nGo to the store and buy some more, 99"W".",j-1);return 0;}
Edit edit: I think these both technically invoke undefined behavior. I ended up being curious about the legal-ness of implicitly declared functions and asked on StackOverflow. According to the answer (and the comments), implicitly declared functions in C89 are legal, but only for specific types of functions, and printf isn't one of those. Learned something new!

#5Cornstalks

Posted 06 July 2013 - 07:26 PM

C99, 365 characters including whitespace (newlines and all), 314 excluding whitespace (I personally think we should be counting whitespace):
#define T ".\nTake one down and pass it around, "
#define B " bottles of beer"
#define b "1 bottle of beer"
#define W B" on the wall"
#define w b" on the wall"
int main(){for(int j=100;j--;)printf(j?j>1?"%d"W", %d"B:w", "b:"No more"W", no more"B,j,j),printf(j?j>1?j>2?T"%d"W".\n\n":T w".\n\n":T"no more"W".\n\n":".\nGo to the store and buy some more, 99"W".",j-1);}
I'm tired. It's time for bed. I might try some more tomorrow.

Edit: I just learned implicit function declaration was made illegal in C99, so my code is an unholy union of C89 and C99. Here's a legal C89 version (added 10 characters):
#define T ".\nTake one down and pass it around, "
#define B " bottles of beer"
#define b "1 bottle of beer"
#define W B" on the wall"
#define w b" on the wall"
int main(){for(int j=100;j--;)printf(j?j>1?"%d"W", %d"B:w", "b:"No more"W", no more"B,j,j),printf(j?j>1?j>2?T"%d"W".\n\n":T w".\n\n":T"no more"W".\n\n":".\nGo to the store and buy some more, 99"W".",j-1);return 0;}

#4Cornstalks

Posted 06 July 2013 - 03:41 AM

C99, 365 characters including whitespace (newlines and all), 314 excluding whitespace (I personally think we should be counting whitespace):
#define T ".\nTake one down and pass it around, "
#define B " bottles of beer"
#define b "1 bottle of beer"
#define W B" on the wall"
#define w b" on the wall"
int main(){for(int j=100;j--;)printf(j?j>1?"%d"W", %d"B:w", "b:"No more"W", no more"B,j,j),printf(j?j>1?j>2?T"%d"W".\n\n":T w".\n\n":T"no more"W".\n\n":".\nGo to the store and buy some more, 99"W".",j-1);}
I'm tired. It's time for bed. I might try some more tomorrow.

#3Cornstalks

Posted 06 July 2013 - 03:33 AM

C99, 365 characters including whitespace, 314 excluding whitespace (I personally think we should be counting whitespace):
#define T ".\nTake one down and pass it around, "
#define B " bottles of beer"
#define b "1 bottle of beer"
#define W B" on the wall"
#define w b" on the wall"
int main(){for(int j=100;j--;)printf(j?j>1?"%d"W", %d"B:w", "b:"No more"W", no more"B,j,j),printf(j?j>1?j>2?T"%d"W".\n\n":T w".\n\n":T"no more"W".\n\n":".\nGo to the store and buy some more, 99"W".",j-1);}
I'm tired. It's time for bed. I might try some more tomorrow.

#2Cornstalks

Posted 06 July 2013 - 03:22 AM

C99, 373 characters including whitespace, 323 excluding whitespace (I personally think we should be counting whitespace):
#define T ".\nTake one down and pass it around, "
#define B " bottles of beer"
#define b " bottle of beer"
#define W B" on the wall"
#define w b" on the wall"
int main(){for(int j=100;j--;)printf(j?j>1?"%d"W", %d"B:"%d"w", %d"b:"No more"W", no more"B,j,j),printf(j?j>1?j>2?T"%d"W".\n\n":T"%d"w".\n\n":T"no more"W".\n\n":".\nGo to the store and buy some more, 99"W".",j-1);}
I'm tired. It's time for bed. I might try some more tomorrow.

#1Cornstalks

Posted 06 July 2013 - 03:14 AM

C99, 387 characters including whitespace, 334 excluding whitespace (I personally think we should be counting whitespace):
#define G ".\nGo to the store and buy some more, "
#define T ".\nTake one down and pass it around, "
#define B " bottles of beer"
#define b " bottle of beer"
#define W B" on the wall"
#define w b" on the wall"
int main(){for(int j=100;j--;)printf(j?j>1?"%d"W", %d"B:"%d"w", %d"b:"No more"W", no more"B,j,j),printf(j?j>1?j>2?T"%d"W".\n\n":T"%d"w".\n\n":T"no more"W".\n\n":G"99"W".",j-1);}
I'm tired. It's time for bed. I might try some more tomorrow.

PARTNERS