Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language LaTeX2e

(Uses only pgf commands and fmtcount)

Date:04/19/10
Author:Joel Berger
URL:https://launchpad.net/~joel-a-berger
Comments:1
Info:n/a
Score: (3.75 in 4 votes)
%% 99 Bottles of Beer on the Wall
%% Distinction: Uses only pgf commands and fmtcount
%% Author: Joel Berger
\documentclass[twocolumn]{article} % Use twocolumn option to ... um ... save paper
%\usepackage{pgffor}
%\usepackage{pgfmath}
%\usepackage{pgfkeys}
\usepackage{tikz} % Loads all three packages above (plus lots of other things)
\usepackage{fmtcount} % Provides commands for converting numbers to words

\begin{document}
%% key-value pairs which, when combined with mathematical tests replace "if" statements
% keys-value pairs to add pluralization (called singular as we test for \x = 1 which is false if
plural)
\pgfkeyssetvalue{/singular/0.0}{s}
\pgfkeyssetvalue{/singular/1.0}{}
% keys-value code pairs to either display the \y converted to text or if \y = 0 say "No more"
\pgfkeys{/text/1.0/.code={\numberstringnum{#1}}}
\pgfkeys{/text/0.0/.code={no more}}

\foreach \x in {99, 98 , ..., 1} {
  \pgfmathequalto{\x}{1} % if \x = 1 set \pgfmathresult = 1.0 else 0.0
  \noindent
  \Numberstringnum{\x} bottle\pgfkeys{/singular/\pgfmathresult} of beer of the wall,\\
  \numberstringnum{\x} bottle\pgfkeys{/singular/\pgfmathresult} of beer.\\
  Take one down pass it around,\\
  \pgfmathtruncatemacro{\y}{\x - 1} % set \y = int(\x - 1)
  \pgfmathgreaterthan{\y}{0} % if \y > 0 set \pgfmathresult = 1.0 else 0.0
  \pgfkeys{/text/\pgfmathresult=\y}\pgfmathequalto{\y}{1}
    bottle\pgfkeys{/singular/\pgfmathresult} of beer on the wall.\\
  \\
}

\end{document}

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
corrected & updatedDavid Short08/07/080

Comments

>>  ella said on 09/24/10 10:17:09

ella The beauty of the leather is always un beatable one in front of any treatment or detailing done later. This Carlos Falchi Gathered Python Pouf Satchel has that kind of natural beauty,coach handbags on sale,coach handbags,coach outlet online,
Nike air max 2010,air max 2009,air max shoes on sale.Buy nike air max shoes on http://www.nikeairmax-1.com low at $62,especially air max 2010,air max 2009,nike air max shoes,nike air max,nike air max 2011
taylor made golf

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: