

Rosetta Code: 99 Bottles of Beer in 117 Programming Languages - tshtf
http://rosettacode.org/wiki/99_Bottles_of_Beer

======
iwr
Apparently, there is no XSLT version. Well, here is one: The XML file: <?xml
version="1.0"?> <?xml-stylesheet type="text/xsl" href="99bottles.xsl"?>
<beer>99</beer>

The XSLT: <xsl:stylesheet version="1.0"
xmlns:xsl="[http://www.w3.org/1999/XSL/Transform>](http://www.w3.org/1999/XSL/Transform>);
<xsl:output method="html" indent="yes"/>

    
    
        <xsl:template match="/">
            <html>
                <head>
                    <title>Beer!</title>
                </head>
                <body>
                    <xsl:call-template name="beer">
                        <xsl:with-param name="bottles" select="/beer"/>
                    </xsl:call-template>
                </body>
            </html>
        </xsl:template>
    
        <xsl:template name="beer">
            <xsl:param name="bottles" />
    
            <xsl:if test="$bottles &gt; 0">
                <p>
                    <xsl:value-of select="$bottles"/>
                    <xsl:choose>
                        <xsl:when test="$bottles = 1" >
                            <xsl:text> bottle of beer on the wall</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:text> bottles of beer on the wall</xsl:text>
                        </xsl:otherwise>
                    </xsl:choose>
                    <br/>
                    <xsl:value-of select="$bottles"/>
                    <xsl:choose>
                        <xsl:when test="$bottles = 1" >
                            <xsl:text> bottle of beer!</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:text> bottles of beer!</xsl:text>
                        </xsl:otherwise>
                    </xsl:choose>
                    <br/>
                    <xsl:text>You take one down, and pass it around</xsl:text>
                    <br/>
                    <xsl:choose>
                        <xsl:when test="($bottles - 1) = 0" >
                            <xsl:text>No bottles of beer on the wall!</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="$bottles - 1"/>
                            <xsl:text> bottles of beer on the wall!</xsl:text>                        
                        </xsl:otherwise>
                    </xsl:choose>
                </p>
                <xsl:call-template name="beer">
                    <xsl:with-param name="bottles" select="$bottles - 1"/>
                </xsl:call-template>
            </xsl:if>
    
        </xsl:template>
    

</xsl:stylesheet>

------
GoneWacko
Obviously I must point out the existence of <http://99-bottles-of-beer.net/>
which claims to have considerably more languages and variations and as such
obviously wins this unwritten competition of site-with-more-implementations-
of-classic-marching-song-reproducing-code.

------
djacobs
I think one of the most sarcastic entries may be the object-oriented solution
in C++:

[http://rosettacode.org/wiki/99_Bottles_of_Beer/C%2B%2B/Objec...](http://rosettacode.org/wiki/99_Bottles_of_Beer/C%2B%2B/Object_Oriented)

Compare with the simple solution:

[http://rosettacode.org/wiki/99_Bottles_of_Beer#The_simple_so...](http://rosettacode.org/wiki/99_Bottles_of_Beer#The_simple_solution_2)

As a recent OO -> functional convert, the comparison was amusing. (Not that
there is anything functional about multiline print statements.)

------
BigZaphod
I'm biased as I'm the creator of Whirl, but one my favorite 99-bottles
implementations might just be this one:
<http://bigzaphod.org/whirl/kang-99.html> And of course, there's the one I did
for another of my silly languages, Taxi: <http://bigzaphod.org/taxi/99.txt> :)
[edit: To clarify, I didn't write the one done in Whirl, that was sent to me
by Kang Seonghoon.)

------
gsivil
I would like to see the preference of other HNers and their arguments based
only on that sample of the language.

If you had only this post to choose a language what would be your preference?
And why?

C looks always archetypal. Simple, crisp and on the point

~~~
mishmash
Perl 5's version made me laugh. Regexes for the iteration, what win.

~~~
IChrisI
For reference, Perl 5's version: <http://99-bottles-of-beer.net/language-
perl-737.html>

My personal favorite is the Malbolge version because it made me read up on
Malbolge :)

<http://99-bottles-of-beer.net/language-malbolge-995.html>

~~~
mishmash
Oh god this is a beautiful hack. I had to download and run it just to believe
it, but jesus it works.

------
afshin
I'm not a very good K programmer, but no K example existed, so I posted mine:

<http://rosettacode.org/wiki/99_Bottles_of_Beer#K>

It fits in a tweet (exactly 140 characters right now ... but it can probably
be shortened).

------
sz
The Inform 7 one is cool. It's almost not recognizable as a program.

Imagine: programming by dictation.

~~~
sz
Closer than one might think?

[http://blog.stephenwolfram.com/2010/11/programming-with-
natu...](http://blog.stephenwolfram.com/2010/11/programming-with-natural-
language-is-actually-going-to-work/)

