99 Bottles Of Beer Challenge With Least Amount Of Characters ?

Started by
95 comments, last by rip-off 9 years, 2 months ago


not sure what you guys are using to do non-whitespace counting, but i don't feel like counting them all to give a number.

Character counting a la the internet.

You are rocking a 330, and you have a capitalization error on the 2nd-to-last line (I'm quibbling, I know, but that capital cost me 5 characters to get right).

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Advertisement


not sure what you guys are using to do non-whitespace counting, but i don't feel like counting them all to give a number.

Character counting a la the internet.

You are rocking a 330, and you have a capitalization error on the 2nd-to-last line (I'm quibbling, I know, but that capital cost me 5 characters to get right).

ah thanks=-). had to bump it up by 3 characters to fix that, and one other mistake: http://codepad.org/aDEAu5R6

edit: here's a c# version: http://ideone.com/S7Hcs5 clocks in at 382 characters.

edit2: managed to reduce it down to 338 characters.

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

Silly little change to get the C# to 330 smile.png

http://ideone.com/D0iVbE

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Ah, but now you have a mistake in your output! You went from 1 bottle of beer to none, without passing it around. tongue.png

He stole my beer!


z = concat
a = " bottle"
e = a ++ "s"

y = "o more"
b 0 = "n" ++ y ++ e
b 1 = "1" ++ a
b n = show n ++ e

c = " of beer"
d = c ++ " on the wall"

f 0 = z [ "N", y, e, d, ", ", b 0, c, ".\nGo to the store and buy some more, ", b 99, d, ".\n" ]
f n = z [ b n, d, ", ", b n, c, ".\nTake one down and pass it around, ", b $ n-1, d, ".\n\n" ]

main = mapM_ (putStr . f) [99,98..0]

260 nonwhitespaces using Haskell.

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!
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

215 non white space characters - thanks Ruby


i = 99
x = " bottles of beer"
y = x + " on the wall, "
z = "Take one down, pass it around, "
a = ".\n"
b = "no more "
while i > 1
    q = i.to_s
    r = (i - 1).to_s
    puts q + y + q + x + a  + z + r + y
    i -= 1
end
q = i.to_s
puts q + y + q + x + a + z + b + y,"No more" + y + b + x + a + "Go to the store and buy some more, 99" + y

I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me.

~ Ralph Waldo Emerson


#include <fstream>
#include <iostream>

void main()
{
std::fstream s;
s.open("b", std::ios::in);

while(s)
{
char c;
s.get(c);
std::cout << c;
}
}

160 characters. Yet I've got the feeling that this one doesn't count...

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.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

The characters from your imported files also count .... tongue.png


import BoB

I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me.

~ Ralph Waldo Emerson

This topic is closed to new replies.

Advertisement