• 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


I have no idea how to reduce it more without cutting corners in output format...

I guess verbose languages like C# and Java pretty much screwed by the criteria themselves.

 

The variable declarations cost you 20 characters, and the length of Console.WriteLine and ToString cost even more.

0

Share this post


Link to post
Share on other sites

I have no idea how to reduce it more without cutting corners in output format...

One common way of doing ToString() in "shorthand" is just doing +"" (in both C# and Java), which will convert the object to a string using ToString().

You could also save more by doing Console.Write() (and adding '\n' to the end) instead of Console.WriteLine(). Also, no need to use g. And some parens aren't needed. Here's a smaller version (296 non-whitespace characters):
 
string
b = " bottles of beer",
c = b.Remove(7, 1),
w = " on the wall",
t = "Take one down and pass it around, ",
n = "o more", x;
for (int a = 99; a>0;)
{
    x = a > 2 ? b : c;
    Console.WriteLine(a + x + w + ", " + a + x + (a-- > 1 ? ".\n" + t + a + (a > 1 ? b : c) + w + ".\n" : "."));
}
Console.Write(t + "n" + n + b + w + ".\n\nN" + n + b + w + ", n" + n + b + ".\nGo to the store and buy some more, 99" + b + w + ".\n");
output

I still think we should be counting whitespace, because it's actually significant. Try running a program with no whitespace... Also, I think C# and Java should include their using/import and class definitions. Edited by Cornstalks
0

Share this post


Link to post
Share on other sites

Wow, thanks Cornstalks for showing me those tricks (mainly string with comma, which I didn't know) :D

0

Share this post


Link to post
Share on other sites

  Closest I can get using "C" and no sleep!
 

#include <stdio.h>


void r(int i)
{
  if(i <= 0)
  {
    printf("No more bottles of beer");
    return;
  }
  printf("%d bottles of beer on the wall, %d bottles of beer\nTake one down and pass it around, %d bottles of beer on the wall\n\n", i, i, i);
  r(i - 1);
}


void main()
{
  r(99);
}
Edited by ByteTroll
0

Share this post


Link to post
Share on other sites
Also, I think C# and Java should include their using/import and class definitions.

 

[url="http://www.gamedev.net/topic/645151-99-bottles-of-beer-challenge-with-least-amount-of-characters/?view=findpost&p=5075623"]I did[/url], they add ~20-30 characters to your character count.

Edited by slicer4ever
0

Share this post


Link to post
Share on other sites

Closest I can get using "C" and no sleep!

*snip*

That doesn't print all the right words. The last verse is wrong (you're not going to the store to buy some more), and when you have 1 bottle left you still say bottles. And when you have 1 bottle of beer on the wall and you take it down, you mysteriously still have 1 bottle of beer on the wall. You're also missing periods.

Do \n etc. Count as one character?

Nope, they count as two.
0

Share this post


Link to post
Share on other sites

 

Closest I can get using "C" and no sleep!

*snip*

That doesn't print all the right words. The last verse is wrong (you're not going to the store to buy some more), and when you have 1 bottle left you still say bottles. And when you have 1 bottle of beer on the wall and you take it down, you mysteriously still have 1 bottle of beer on the wall. You're also missing periods.

Do \n etc. Count as one character?

Nope, they count as two.

 

 

Ah snap! I didn't even notice that ;P  I shall fix it.

0

Share this post


Link to post
Share on other sites

 

 

Also, I think C# and Java should include their using/import and class definitions.

 

I did, they add ~20-30 characters to your character count.

 

 

Actually, with the Roslyn shell you no longer need the surrounding class / Main function cruft, just as if you were using the python shell. Granted, you should still include the using statements, since they're required.

 

Also, I see your 300+ C# entry and raise you 250 (even beats some of the other languages)  biggrin.png

string f="{0:#;;",e=".\n",o="s;s;''} of beer",w=" on the wall",n="o more} bottle",x=n+"{1:"+o;
for(int a=99;a>=0;)System.Console.WriteLine(f+'N'+x+w+", "+f+'n'+x+e+
"{1:Take one down and pass it around;Go to the store and buy some more}, {1:#;99;n"+n+"{2:"+o+w+e,a,a-1,--a-1);

It doesn't require the conditional operator either, which is nifty.

 

impressive, i wrapped it up to be compilable with ideone: [url]http://ideone.com/MX82jD[/url] adding the extra fluff for ideone's compiler bumps it up to 288, but still, quite impressive mate.

0

Share this post


Link to post
Share on other sites

Also, I see your 300+ C# entry and raise you 250 (even beats some of the other languages)  biggrin.png

string f="{0:#;;",e=".\n",o="s;s;''} of beer",w=" on the wall",n="o more} bottle",x=n+"{1:"+o;
for(int a=99;a>=0;)System.Console.WriteLine(f+'N'+x+w+", "+f+'n'+x+e+
"{1:Take one down and pass it around;Go to the store and buy some more}, {1:#;99;n"+n+"{2:"+o+w+e,a,a-1,--a-1);
It doesn't require the conditional operator either, which is nifty.

That is a thing of beauty.
0

Share this post


Link to post
Share on other sites

Also, I see your 300+ C# entry and raise you 250 (even beats some of the other languages)  biggrin.png

string f="{0:#;;",e=".\n",o="s;s;''} of beer",w=" on the wall",n="o more} bottle",x=n+"{1:"+o;
for(int a=99;a>=0;)System.Console.WriteLine(f+'N'+x+w+", "+f+'n'+x+e+
"{1:Take one down and pass it around;Go to the store and buy some more}, {1:#;99;n"+n+"{2:"+o+w+e,a,a-1,--a-1);

It doesn't require the conditional operator either, which is nifty.

You, sir, just blew my mind

Mind-Blown.jpg

 

Edit: this thread needs to be somewhere where I can upvote... I'm learning all sorts of tricks in this wide variety of languages.

Edited by Cornstalks
2

Share this post


Link to post
Share on other sites


Edit: this thread needs to be somewhere where I can upvote... I'm learning all sorts of tricks in this wide variety of languages.

Your wish is my command.

 

Plus, this thread seemed to qualify from the beginning.

0

Share this post


Link to post
Share on other sites

 

Also, I see your 300+ C# entry and raise you 250 (even beats some of the other languages)  biggrin.png
string f="{0:#;;",e=".\n",o="s;s;''} of beer",w=" on the wall",n="o more} bottle",x=n+"{1:"+o;
for(int a=99;a>=0;)System.Console.WriteLine(f+'N'+x+w+", "+f+'n'+x+e+
"{1:Take one down and pass it around;Go to the store and buy some more}, {1:#;99;n"+n+"{2:"+o+w+e,a,a-1,--a-1);

It doesn't require the conditional operator either, which is nifty.

 

 

What? Wait... what? Can somebody translate that for me, because some things I didn't see yet in C# (or I saw but didn't have the need to use hence forgot it).

0

Share this post


Link to post
Share on other sites


What? Wait... what? Can somebody translate that for me, because some things I didn't see yet in C# (or I saw but didn't have the need to use hence forgot it).

It's mostly some very clever applications of string formatting.

 

That said, Mike clearly knows way more fun facts about string formatting than I do :)

1

Share this post


Link to post
Share on other sites

 


What? Wait... what? Can somebody translate that for me, because some things I didn't see yet in C# (or I saw but didn't have the need to use hence forgot it).

It's mostly some very clever applications of string formatting.

 

That said, Mike clearly knows way more fun facts about string formatting than I do smile.png

 

 

Oh, the things you learn by trawling through the MSDN documentation at random :)   So many bits of the BCL are completely unknown to most people.

0

Share this post


Link to post
Share on other sites

Thanks for thorough explanation. I'm still stunned at that "black magic", and I believe I won't ever have to use that kind of formatting XD

0

Share this post


Link to post
Share on other sites

It's actually pretty common in business applications. Sometimes people want negatives done with parenthesis around them, or instead of displaying a 0, a single dash. For rich text formatting it's also common to also specify color as part of these, so you can have something like negatives also be red. 

0

Share this post


Link to post
Share on other sites
n=:<'no more'
a=:(n,~<1)0}(>:(;"0)+)i.99
b=:<'bottles of beer'
o=:<'on the wall'
t=:<'take one down, pass it around'
c=:(99#b),"0~{."1 a
(|.c,"1 o,"1 c,"1 t,"1(}."1 a),"1 b,o),o,~b,~n,b,o,n,b,'go to the store and buy some more';99
 
201 non-whitespace, 230 whitespace characters in J. I could probably get it shorter but I've already forgotten how it works.
2

Share this post


Link to post
Share on other sites

I've got a Python3 solution of 160 non-whitespace characters or 162 if you count whitespace:

 

[source]import urllib.request,re

print(re.sub('<br/?> ?','\n',re.sub('</p>\n?<p>','\n\n',urllib.request.urlopen('http://goo.gl/PEeK').read().decode('utf-8')[3592:-1028])))[/source]

 

Requires an internet connection wink.png

2

Share this post


Link to post
Share on other sites

You blew my 250 non white space code right out of the water ( Ruby ) !!

Right now I am seeing if I can abuse Python 2.7 into submission, but I see it's going to be tough to get under 218

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