99 Bottles Of Beer Challenge With Least Amount Of Characters ?

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

99 Bottles Of Beer Project is a collection of the "99 Bottles Of Beer" song written in over 1,500 different programming languages.

I was wondering, what is the shortest program you can write, that outputs the whole song "99 Bottles Of Beer" ( total characters ) ?

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

Advertisement

c++ version, smallest that i can come up with: http://codepad.org/dDT47DTr

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

I see your 473 non-whitespace characters, and raise you 331.

(Yes, it's permitted in the C++ standard to not include the return statement in the main() function)

[Edit:] Got it to 314 non-whitespace characters. Still has the flaw @slicer mentions below. =(...

I see your 473 non-whitespace characters, and raise you 331.

(Yes, it's permitted in the C++ standard to not include the return statement in the main() function)

aha! but you missed that instead of "0 bottles of beer on the wall." it's suppose to be: "no more bottles of beer on the wall."

=-)

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.
I'm disappointed I haven't been seeing more obfuscated C++ tricks like using the preprocessor definitions and implicit string concatenation to shrink the string literals. For instance, "bottles of beer" is repeated in a number of places in both of those code samples so you can use things like

#define B "bottles of beer"
printf("No more " B " on the wall, no more " B ".\n"
You guys are actually producing readable code.

I see your 473 non-whitespace characters, and raise you 331.

[Edit:] Got it to 314 non-whitespace characters. Still has the flaw @slicer mentions below. =(...

By the powers vested in me by Python, I see your 314 and raise you 274.

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

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

I see your 473 non-whitespace characters, and raise you 331.

[Edit:] Got it to 314 non-whitespace characters. Still has the flaw @slicer mentions below. =(...

By the powers vested in me by Python, I see your 314 and raise you 274.

I don't know Python, but following from what SiCrane said, could you perhaps make line 6 stick an 's' into the string a, removing the need for a substantially-identical string b?

EDIT: This seems to work with fewer characters, and I'm sure someone who has actually used Python, you know, ever, could do this in a smarter way.


a = 'bottles of beer'
w = 'on the wall.\n'

def D(i):
	return i if i!=0 else 'no more'

def Q(i):
	return a if i!=1 else "".join(a.split("s"))

def C(i):
	return '\nTake one down and pass it around,' if i>0 else '\nGo to the store and buy some more,'

for i in range(99,-1,-1):
    print D(i), Q(i), 'on the wall,', D(i), Q(i)+'.', C(i), D(i-1), Q(i-1), w

#print 'No more', b, 'on the wall, no more', b+'.'+C(i), '99', b, w

EDIT: Oops, I must have stolen swiftcoder's code to make that change at a moment when it was broken, so there's an off-by-one error in mine.

-~-The Cow of Darkness-~-

I don't know Python, but following from what SiCrane said, could you perhaps make line 6 stick an 's' into the string a, removing the need for a substantially-identical string b?

Yeah, but unfortunately I also had a couple of bugs, so even with that, I had to go back up to 290 to fix them...

Edit: that's still 30 characters shorter than the shortest complete example on the site, so I guess I am happy.

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

I'm disappointed I haven't been seeing more obfuscated C++ tricks like using the preprocessor definitions and implicit string concatenation to shrink the string literals. For instance, "bottles of beer" is repeated in a number of places in both of those code samples so you can use things like


#define B "bottles of beer"
printf("No more " B " on the wall, no more " B ".\n"
You guys are actually producing readable code.

challanged accepted: http://codepad.org/jHzuL4zd

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.

edit: made minor fix.

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

This topic is closed to new replies.

Advertisement