• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
RLS0812

99 Bottles Of Beer Challenge With Least Amount Of Characters ?

96 posts in this topic

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 ) ?

Edited by Shippou
0

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)

 

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

Edited by Servant of the Lord
0

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

 

=-)

0

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

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.

0

Share this post


Link to post
Share on other sites

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

0

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
0

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
0

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: [url]http://codepad.org/jHzuL4zd[/url]

 

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
0

Share this post


Link to post
Share on other sites


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

1

Share this post


Link to post
Share on other sites

 


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: [url]http://codepad.org/aDEAu5R6[/url]

 

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

 

edit2: managed to reduce it down to 338 characters.

Edited by slicer4ever
0

Share this post


Link to post
Share on other sites

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!

0

Share this post


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

0

Share this post


Link to post
Share on other sites
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! Edited by Cornstalks
0

Share this post


Link to post
Share on other sites

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
Edited by Shippou
0

Share this post


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

Edited by Juliean
0

Share this post


Link to post
Share on other sites

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

import BoB
0

Share this post


Link to post
Share on other sites

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 you would perhaps extend it to produce Pascal's triangle when feeding it a non-empty source file, it might become a serious contender to PacTri as language to be used in these kinds of contests.

2

Share this post


Link to post
Share on other sites


215 non white space characters - thanks Ruby

You are missing the singular case of bottles/bottle, and you have a comma instead of a period at the end of every second line.

 

The "canonical" output has 89 characters in unique runs, so entropy is the limiting factor in program size. One can reduce the size of the program pretty substantially by cutting corners in the output...

2

Share this post


Link to post
Share on other sites

C# version:

string b, w, t, n, c, g;
b = " bottles of beer";
c = b.Remove(7, 1);
w = " on the wall";
t = "Take one down and pass it around, ";
n = "o more";
for (int a = 99; a > 0; a--)
{
   g = a.ToString();
   Console.WriteLine(g + (a > 2 ? b : c) + w + ", " + g + (a > 2 ? b : c) + ((a > 1) ? (".\n" + t + (a - 1).ToString() + (a > 2 ? b : c) + w + ".\n") : "."));
}
Console.WriteLine(t + "n" + n + b + w + ".\n\nN" + n + b + w + ", n" + n + b + ".\nGo to the store and buy some more, 99" + b + w + ".");

349 non-whitespace characters. I have no idea how to reduce it more without cutting corners in output format...

 

Full solution is here, as is the result. I didn't count anything besides pure solution.

0

Share this post


Link to post
Share on other sites

Here is the corrected version ... 250 characters . I'm going to see if I can slim that down a bit later today.

i = 99
c = "of beer"
d = "."
e = ", "
f = " on the wall"
x = " bottles " + c
y = x + f
z = "Take one down, pass it around, "
a = " bottle of " + c
b = "no more"
while i > 1
    q = i.to_s
    r = (i - 1).to_s
    puts q + y + e +  q + x + d, z + r + y + d
    i -= 1
end
puts r + a + f + e + r + a + d, z + b + y + d,b.capitalize + y + e + b + x + d,"Go to the store and buy some more, 99" + y + d
Edited by Shippou
0

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0