Jump to content
  • Advertisement
Sign in to follow this  
RLS0812

99 Bottles Of Beer Challenge With Least Amount Of Characters ?

This topic is 1615 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement

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. =(...

Edited by Servant of the Lord

Share this post


Link to post
Share on other sites

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

 

=-)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

 

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.

Edited by cowsarenotevil

Share this post


Link to post
Share on other sites

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.

Edited by swiftcoder

Share this post


Link to post
Share on other sites

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.

Edited by slicer4ever

Share this post


Link to post
Share on other sites

This topic is 1615 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!