Apparently our syntax highlighter is discriminatory towards klingons.
99 Bottles Of Beer Challenge With Least Amount Of Characters ?
Nobody said we had to use a real language. Therefore, zero characters, using the newly created "bottles of beer" language..
The specification of the "bottles of beer" language states that:
An empty source file shall produce a program which prints out the lyrics of the "99 bottles of beer" song. The behaviour of non-empty source files is unspecified.
Thank you.
Someone has already kinda-sorta beat you to the punch
I'm not sure if anyone has mentioned this in the thread, but... introducing HQ9+
9
99 Bottles of Beer in 1 character.
EDIT: Ehh, what the heck, I thought I'd join the fun. My weapon of choice is C:
#define z(s,t) h(s,t," bottle%s of beer"," on the wall",i:,"o more",i==1?"":"s")
#define h(a,q,b,c,d,e,f) printf(a b c", "a b".\n%s, "q b c".\n\n",i?d"N"e,f,i!=0?d"n"e,f,i?"Take one down and pass it around":"Go to the store and buy some more",i==0?99:i!=1?i-1:"n"e,i==2?"":"s")
main(){int i=99;for(;i>=0;i--)i==0?z("%s","%i"):i==1?z("%i","%s"):z("%i","%i");}
Also, I got it on codepad to show that it in fact executes correctly: http://codepad.org/CIeL7PZm
It is 358 characters I think. I compiled it using GCC with both -std=99 and -std=89 and the results are the same. It compiles with many warnings but it runs nonetheless.
Fun fact, I ran GCC -E when I was testing the macros for correctness, and they expand to over 1000 characters of code XD
#include <stdio.h>
int main (void)
{
#define P(A)printf(A,i,i,i)
#define B(A,P)#A" bottle"#P" of beer on the wall"
#define V(P)B(%d,P)", %d bottle"#P" of beer.\nTake one down and pass it around, "
int i=99;
P(V(s));
#define R B(%d,s)".\n\n"V(s)
while(--i>1)
P(R);
#define R B(1,\?\b)".\n\n"V(\?\b)
P(R B(no more,s)".\n\n"B(No more,s)", no more bottles of beer.\nGo to the store and buy some more, "B(99,s)".\n");
}
378 characters including significant whitespace, 396 with the #include . Output is perfect including caps, punctuation, newlines and final verses. I could probably hoist out a few #defines, or #define the #defines and save another 20-30 chars, but I'm weary of this exercise for the moment Gotta love code that only reads top to bottom!
#include <stdio.h> int main (void) { #define P(A)printf(A,i,i,i) #define B(A,P)#A" bottle"#P" of beer on the wall" #define V(P)B(%d,P)", %d bottle"#P" of beer.\nTake one down and pass it around, " int i=99; P(V(s)); #define R B(%d,s)".\n\n"V(s) while(--i>1) P(R); #define R B(1,\?\b)".\n\n"V(\?\b) P(R B(no more,s)".\n\n"B(No more,s)", no more bottles of beer.\nGo to the store and buy some more, "B(99,s)".\n"); }
378 characters including significant whitespace, 396 with the #include . Output is perfect including caps, punctuation, newlines and final verses. I could probably hoist out a few #defines, or #define the #defines and save another 20-30 chars, but I'm weary of this exercise for the moment Gotta love code that only reads top to bottom!
Codepad seems to be messing up your output. At the 1 bottle of beer line, it prints bottle? instead of bottle, although my console seems to get it right.
Apparently our syntax highlighter is discriminatory towards klingons.
You should fix that Senior Moderator guy.
Codepad seems to be messing up your output. At the 1 bottle of beer line, it prints bottle? instead of bottle, although my console seems to get it right.
It must not support the escape sequence for backspace then. I have to feed one of my macros, and I do so with a \?\b (question mark, backspace) sequence to keep it happy. I suppose I could have just used an \a (alert/bell) sequence and saved 4 characters, but I felt like that was cheating.
Cleaning up, hoisting " on the wall", and using \a, now I've got:
#include <stdio.h>
int main()
{
#define P(M)printf(M,i,i,i) //27:27
#define W " on the wall" //24:51
#define B(A,S)#A" bottle"#S" of beer" //37:88
#define V(S)B(%d,S)W", "B(%d,S)".\nTake one down and pass it around, " //70:158
int i = 99; //11:169
P(V(s)); //8:177
#define R(S)B(%d,S)W".\n\n"V(S) //31:208
while (--i>1) //13:221
P(R(s)); //8: 229
P(R(\a)B(no more, s)W".\n\n"B(No more, s)W", "B(no more, s)".\nGo to the store and buy some more, "B(99, s)W"."); //109:338
} //+18 (#include) +12 (main) = 370 characters
Which is 338 characters for the body, and 370 in total (#include, main, body), including significant whitespace. And its actually fairly reasonable to follow.
Just throwing my hat in the ring, though it's not the shortest:
#include<iostream>
#include<sstream>
using namespace std;
string m="o more",v=" bottle",t=" of beer",s=" on the wall";
string a(int n,int c=0)
{
stringstream b;
b << n;
return (n?b.str():(c?"N":"n")+m)+(n==1?v:v+"s");
}
int main()
{
for(int l=99;l>-1;--l)
{
cout << a(l,1)+t+s+", "+a(l)+t+".\n"+(l?"Take one down and pass it around, ":"Go to the store and buy some more, ")+(a(l?l-1:99))+t+s+".\n\n";
}
}
370 characters, 332 without "any" whitespace.
I have yet to see some one use WhiteSpace ...
http://www.99-bottles-of-beer.net/language-whitespace-154.html