Rosetta Code: 99 Bottles of Beer in 117 Programming Languages
rosettacode.org
rosettacode.org
The XSLT: <xsl:stylesheet version="1.0" xmlns:xsl="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 > 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>http://rosettacode.org/wiki/99_Bottles_of_Beer/C%2B%2B/Objec...
Compare with the simple solution:
http://rosettacode.org/wiki/99_Bottles_of_Beer#The_simple_so...
As a recent OO -> functional convert, the comparison was amusing. (Not that there is anything functional about multiline print statements.)
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
My personal favorite is the Malbolge version because it made me read up on Malbolge :)
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).
Imagine: programming by dictation.
http://blog.stephenwolfram.com/2010/11/programming-with-natu...