99 Bottles of Beer
On a humor mailing list I was on in early '94, some nitwit posted the entire lyrics to "99 Bottles of Beer on the Wall." Needless to say, this was seen as a waste of bandwidth. The first protest was that the job could have been accomplished with six lines of BASIC and here were the six lines:
10 REM Basic version of 99 bottles of beer 20 FOR X=100 TO 1 STEP -1 30 PRINT X;"Bottle(s) of beer on the wall,";X;"bottle(s) of beer" 40 PRINT "Take one down and pass it around," 50 PRINT X-1;"bottle(s) of beer on the wall" 60 NEXTHowever, the complainer made the mistake of slighting C++ programmers, so I rose to the occasion with my version of "99 Bottles" in C++. It opened the floodgates and programmers from all over the world gave different versions in assorted languages. I regret that I don't have the names to credit any of the programmers. However, if you spot your handiwork in the collection, please send me your name and mail address in the form of a comment in the appropriate language. (Or ask me to remove the code... I'm sure somebody can write a replacement.)
I'd like to expand this little "work of art" with other programming languages. (Hmm... 99 of them would be perfect!) If you've got a version of "99 Bottles" that isn't in this collection, please e-mail me and I'll add it. If you could put your name in the form of your language's comment style, that would be great. Painfully missing from this list are Logo, Pilot, Focal, TECO and Jovial.
Since starting this project, I've gotten beer in some obscure containers. For the sake of the unwashed masses, I've included brief descriptions of the languages which, hopefully, won't detract from the code that follows. I also picked up the following gem which isn't really a programming language, but may appeal to the mathematically inclined. (For the non mathematically inclined, you might replace Aleph-null with infinity)
Aleph-null bottles of beer on the wall,
Aleph-null bottles of beer
You take one down & pass it around
Aleph-null bottles of beer
Tim Robinson
timtroyr@ionet.net
Back to the Funhouse
// C++ version of 99 Bottles of beer
// programmer: Tim Robinson timtroyr@ionet.net
#include <fstream.h>
int main()
{
int bottles = 99;
while ( bottles > 0 )
{
cout << bottles << " bottle(s) of beer on the wall," << endl;
cout << bottles << " bottle(s) of beer." << endl;
cout << "Take one down, pass it around," << endl;
cout << --bottles << " bottle(s) of beer on the wall." << endl;
}
return 0;
}
// C++ version of 99 Bottles of Beer, object oriented paradigm
// programmer: Tim Robinson timtroyr@ionet.net
#include <fstream.h>
enum Bottle { BeerBottle };
class Shelf {
unsigned BottlesLeft;
public:
Shelf( unsigned bottlesbought )
: BottlesLeft( bottlesbought )
{}
void TakeOneDown()
{
if (!BottlesLeft)
throw BeerBottle;
BottlesLeft--;
}
operator int () { return BottlesLeft; }
};
int main( int, char ** )
{
Shelf Beer(99);
try {
for (;;) {
char *plural = (int)Beer !=1 ? "s" : "";
cout << (int)Beer << " bottle" << plural
<< " of beer on the wall," << endl;
cout << (int)Beer << " bottle" << plural
<< " of beer," << endl;
Beer.TakeOneDown();
cout << "Take one down, pass it around," << endl;
plural = (int)Beer !=1 ? "s":"";
cout << (int)Beer << " bottle" << plural
<< " of beer on the wall." << endl;
}
}
catch ( Bottle ) {
cout << "Go to the store and buy some more," << endl;
cout << "99 bottles of beer on the wall." << endl;
}
return 0;
}
* 99 BOTTLES OF BEER IN SNOBOL (UNTESTED)
BEER = 99
MOREBEER OUTPUT = BEER ' BOTTLES OF BEER ON THE WALL'
OUTPUT = BEER ' BOTTLES OF BEER'
OUTPUT = 'TAKE ONE DOWN, PASS IT AROUND'
BEER = BEER - 1
OUTPUT = BEER ' BOTTLES OF BEER ON THE WALL'
GT(BEER,0) : S(MOREBEER)
OUTPUT = 'NO MORE BOTTLES OF BEER ON THE WALL'
OUTPUT = 'NO MORE BOTTLES OF BEER'
OUTPUT = 'GO TO THE STORE AND BUY SOME MORE'
OUTPUT = '99 BOTTLES OF BEER'
END
% How to do 99 Bottles of Beer in Postscript.
% This doesn't go out to the printer. You'd need to hook a serial port
% to your LaserPrinter or Postscript typesetter
/beer {
/bottles 7 string def
99 -1 1
{ dup bottles cvs print ( bottles of beer on the wall, )
bottles print (bottles of beer. Take one down, pass it around, )
1 sub bottles cvs print ( bottles of beer on the wall. )
} for
(No more bottles of beer on the wall, no more bottles of beer. )
(Go to the store and buy some more... 99 bottles of beer) } def
(* Pascal version of 99 Bottles of beer *)
program BottlesOfBeers(input, output);
var
bottles: integer;
begin
bottles := 99;
repeat
WriteLn(bottles, ' bottles of beer on the wall, ',
bottles, ' bottles of beer.');
Write('Take one down, pass it around, ');
bottles := bottles-1;
WriteLn(bottles, ' bottles of beer on the wall.');
until (bottles = 1);
WriteLn('1 bottle of beer on the wall, one bottle of beer.');
WriteLn('Take one down, pass it around,'
' no more bottles of beer on the wall')
end.
IDENTIFICATION DIVISION.
PROGRAM-ID.BOTTLES_OF_BEER.
AUTHOR.DONALD FRASER.
*
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. VAX.
OBJECT-COMPUTER. VAX.
*
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT OUTPUT-FILE
ASSIGN TO BEERS_ON_THE_WALL.
*
DATA DIVISION.
FILE SECTION.
FD OUTPUT-FILE
LABEL RECORDS ARE OMITTED.
01 BEERS-OUT PIC X(133).
*
WORKING-STORAGE SECTION.
01 FLAGS-COUNTERS-ACCUMULATORS.
05 FLAGS.
10 E-O-F PIC 9.
88 END-OF-FILE VALUE 1.
05 COUNTERS.
10 BOTTLES PIC 999
VALUE 0.
01 RECORD-OUT.
05 LINE1.
10 NUMBER-OF-BEERS-1 PIC ZZ9.
10 PIC X(28)
VALUE "BOTTLES OF BEER IN THE WALL ".
10 PIC
X
VALUE ",".
10 NUMBER-OF-BEERS-2 PIC ZZ9.
10 PIC
X.
10 PIC X(17)
VALUE "BOTTLES OF BEER.".
05 LINE2.
10 PIC X(34)
VALUE "TAKE ONE DOWN AND PASS IT ARROUND ".
10 NUMBER-OF-BEERS-3 PIC ZZ9.
10 PIC X.
10 PIC X(28)
VALUE "BOTTLES OF BEER IN THE WALL".
*
PROCEDURE DIVISION.
DRIVER-MODULE.
PERFORM INITIALIZATION.
PERFORM PROCESS UNTIL END-OF-FILE.
PERFORM TERMINATION.
STOP RUN.
*
INITIALIZATION.
OPEN OUTPUT OUTPUT-FILE.
ADD 100 TO BOTTLES.
*
PROCESS.
IF BOTTLES = 0 THEN
COMPUTE E-O-F = 1
ELSE PERFORM WRITE-ROUTINE
END-IF.
*
TERMINATION.
CLOSE OUTPUT-FILE.
*
WRITE-ROUTINE.
MOVE BOTTLES TO NUMBER-OF-BEERS-1, NUMBER-OF-BEERS-2.
COMPUTE BOTTLES = BOTTLES - 1.
WRITE BEERS-OUT FROM LINE1.
MOVE BOTTLES TO NUMBER-OF-BEERS-3.
WRITE BEERS-OUT FROM LINE2.
/* REXX Version of the Bottles program */
TRACE OFF
X=100
DO WHILE X>=0
SAY X 'Bottle(s) of beer on the wall,' X 'Bottle(s) of beer'
SAY 'Take one down and pass it around,'
X=X-1
END
/* C Version of 99 Bottles of Beer */
main()
{
int bot_num;
int i;
printf ("How many bottles? ");
scanf ("%d", &bot_num);
for ( i=bot_num; i>=1; --i )
{
if ( i != bot_num )
if ( i == 1 ) printf ("%d bottle of beer on the wall.\n", i);
else printf ("%d bottles of beer on the wall.\n", i);
if ( i == 1 )
{
printf ("%d bottle of beer on the wall, %d bottle of beer.", i,i);
printf (" Take one down, pass it around.\n");
printf ("No more bottles of beer on the wall.\n");
}
else
{
printf ("%d bottles of beer on the wall, %d bottles of beer.", i, i);
printf (" Take one down, pass it around.\n");
}
}
}
/* And here is the PL/I version: */
BOTTLES: PROC OPTIONS(MAIN);
DCL NUM_BOT FIXED DEC(3);
DCL PHRASE1 CHAR(100) VAR;
DCL PHRASE2 CHAR(100) VAR;
DCL PHRASE3 CHAR(100) VAR;
DO NUM_BOT = 100 TO 1 BY -1;
PHRASE1 = NUM_BOT||' Bottles of Beer on the wall,';
PHRASE2 = NUM_BOT||' Bottles of Beer';
PHRASE3 = 'Take one down and pass it around';
DISPLAY(PHRASE1||PHRASE2);
DISPLAY(PHRASE3);
END;
PHRASE1 = 'No more Bottles of Beer on the wall, ';
PHRASE2 = 'No more Bottles of Beer';
PHRASE3 = 'Go to the store and buy some more';
DISPLAY(PHRASE1||PHRASE2);
DISPLAY(PHRASE3);
END BOTTLES;
/* Ada version of 99 Bottles of Beer */
with TEXT_IO; use TEXT_IO;
procedure BOTTLES is
package INT_IO is new INTEGER_IO (INTEGER);
use INT_IO;
COUNT : INTEGER := 99;
begin
while COUNT > 0 loop
PUT (COUNT,WIDTH=>0); PUT_LINE (" bottles of beer on the wall,");
PUT (COUNT,WIDTH=>0); PUT_LINE (" bottles of beer.");
PUT_LINE ("Take one down and pass it around.");
COUNT := COUNT - 1;
if COUNT = 0 then
PUT_LINE("No bottles of beer on the wall!");
else
PUT (COUNT,WIDTH=>0); PUT_LINE (" bottles of beer on the wall.");
end if;
NEW_LINE;
end loop;
end BOTTLES;
@ECHO OFF REM * Batch version of the Bottles program - Main loop * :LOOP SET X=%1 IF "%X%"=="0" GOTO LAST ECHO %X% Bottles of beer on the wall, %X% Bottles of beer ECHO Take one down and pass it around SHIFT IF "%1"=="" GOTO END GOTO LOOP :LAST ECHO No more Bottles of beer on the wall, No more bottles of beer ECHO Go to the store and buy some more :END
#!/bin/csh # # C-Shell script version of 99 Bottles of Beer # set i = 100 while ($i > 0) echo -n $i " bottles of beer on the wall" echo $i " bottles of beer......" set i = `expr $i - 1` echo -n "take one down pass it around, " $i echo "bottles of beer on the wall" end
# # Version #2 C-Shell version of 99 Bottles of Beer # foreach i (9 8 7 6 5 4 3 2 1 0) foreach j (9 8 7 6 5 4 3 2 1 0) echo -n $i$j " bottles of beer on the wall" echo $i$j " bottles of beer" echo -n $i$j " take one down pass it around..." echo $i$j " bottles of beer on the wall" end end
H*
H* RPG/400 VERSION OF THE BOTTLES PROGRAM *
H*
FSCREEN O F 80 WORKSTN
C MOVE 100 X 30
C X DOWGE0
C EXCPT
C SUB 1 X
C END
C SETON LR
OSCREEN E
O X 3
O 26 'BOTTLES OF BEER ON THE'
O 31 'WALL,'
O X 36
O 53 'BOTTLES OF BEER'
O E
O 22 'TAKE ONE DOWN AND PASS'
O 32 'IT AROUND'
; BOTTLES.ASM - 80x86 version of the bottles of beer program
cr equ 10d
lf equ 13d
cseg segment byte
assume cs:cseg, ds:cseg
org 100h
main proc
ini:
mov si, 50
lus:
mov ax, si
call int2strn
mov ah, 40h
mov bx, 1
mov cx, Bot2_Len
mov dx, offset Bot2_Msg
int 21h
mov ax, si
call int2strn
mov ah, 40h
mov bx, 1
mov cx, Bottle_Len
mov dx, offset Bottle_Msg
int 21h
mov ax, si
call int2strn
mov ah, 40h
mov bx, 1
mov cx, Pass_Len
mov dx, offset Pass_Msg
int 21h
sub si, 1
jnz lus
mov ah, 40h
mov bx, 1
mov cx, None_Len
mov dx, offset None_Msg
int 21h
mov ax, 4c00h
int 21h
main endp
int2strn proc near
mov cx,10
xor dx,dx
div cx
or al, al
jz next
push dx
mov dl,al
add dl,30h
mov ah,2
int 21h
pop dx
next:
mov ah,2
add dl,30h
int 21h
ret
int2strn endp
Bottle_Msg db ' bottles of beer on the wall, '
Bottle_Len equ $ - Bottle_Msg
Pass_Msg db ' bottles of beer. Take one down, pass it around.', cr, lf
Pass_Len equ $ - Pass_Msg
Bot2_Msg db ' bottles of beer on the wall.', cr, lf
Bot2_Len equ $ - Bot2_Msg
None_Msg db 'No more bottles of beer on the wall.', cr, lf
None_Len equ $ - None_Msg
cseg ends
end ini
; Here is the Macintosh WordPerfect macro language version. Assign (Var01;99) Repeat Type Var (Var01) Type ( bottles of beer on the wall. ) Type Var (Var01) Type ( bottles of beer. ) Type (Take one down, pass it around. ) Assign (Var01;Var01-1) Type Var (Var01) Type ( bottles of beer on the wall.) Hard Return Until (Var01=0)
; Vax VMS version of 99 Bottles of Beer
.TITLE BOTTLES
BOTT: .ASCIZ / BOTTLES OF BEER ON THE WALL,/
BOTT2: .ASCIZ / BOTTLES OF BEER, ONE DOWN, PASS IT AROUND/
BOTT3: .ASCIZ / BOTTLES OF BEER ON THE WALL./
ZERO: .LONG 48
.ENTRY START,0
MOVL #^A'9',R2
MOVL #^A'9',R3
LOOP: .TTYOUT R3
.TTYOUT R2
.PUTSTR BOTT
.TTYOUT R3
.TTYOUT R2
.PUTSTR BOTT2
CMPL R2,ZERO
BEQL DECR
CONT1: DECL R2
.TTYOUT R3
.TTYOUT R2
.PUTSTR BOTT3
CMPL R3,ZERO
BEQL CHECK
BRB LOOP
DECR: DECL R3
MOVL #^A':',R2
BRB CONT1
CHECK: CMPL R2,ZERO
BGTR LOOP
$EXIT_S
.END START
$ I=100 $ FIRSTLOOP: $ IF (I.EQ. 1) THEN GOTO LAST_BOTTLE $ WRITE SYS$OUTPUT I," BOTTLES OF BEER ON THE WALL" $ WRITE SYS$OUTPUT I," BOTTLES OF BEER" $ WRITE SYS$OUTPUT "IF ONE OF THEM SHOULD HAPPEN TO FALL" $ WRITE SYS$OUTPUT I-1," BOTTLE OF BEER ON THE WALL" $ WRITE SYS$OUTPUT " " $ I=I-1 $ GOTO FIRSTLOOP $ LAST_BOTTLE: $ WRITE SYS$OUTPUT "1 BOTTLE OF BEER ON THE WALL" $ WRITE SYS$OUTPUT "1 BOTTLE OF BEER" $ WRITE SYS$OUTPUT "IF IT SHOULD HAPPEN TO FALL" $ WRITE SYS$OUTPUT "NO MORE BOTTLES OF BEER ON THE WALL"
; VMS DCL version of 99 Bottles of Beer $ I=100 $ FIRSTLOOP: $ C=0 $ L=1 $ PAUSE: $ C=C+1 $ IF (I.EQ. 1) THEN GOTO LAST_BOTTLE $ IF (C .EQ. 1500) THEN GOTO FIRSTCLEAN $ GOTO PAUSE $ FIRSTCLEAN: $ GOTO WIPESCN $ FIRSTLINE: $ WRITE SYS$OUTPUT I," bottles of beer on the wall," $ C=0 $ L=2 $ FIRSTPAUSE: $ C=C+1 $ IF (C .EQ. 2000) THEN GOTO SECONDCLEAN $ GOTO FIRSTPAUSE $ SECONDCLEAN: $ GOTO WIPESCN $ SECONDLINE: $ WRITE SYS$OUTPUT I," bottles of beer." $ C=0 $ L=3 $ SECONDPAUSE: $ C=C+1 $ IF (C .EQ. 1500) THEN GOTO THIRDCLEAN $ GOTO SECONDPAUSE $ THIRDCLEAN: $ GOTO WIPESCN $ THIRDLINE: $ WRITE SYS$OUTPUT "If one of them should happen to fall...." $ C=0 $ L=4 $ THIRDPAUSE: $ C=C+1 $ IF (C .EQ. 1500) THEN GOTO FOURTHCLEAN $ GOTO THIRDPAUSE $ FOURTHCLEAN: $ GOTO WIPESCN $ FOURTHLINE: $ WRITE SYS$OUTPUT I-1," bottles of beer on the wall." $ I=I-1 $ GOTO FIRSTLOOP $ LAST_BOTTLE: $ C=0 $ L=5 $ FOURTHPAUSE: $ C=C+1 $ IF (C .EQ. 1500) THEN GOTO FITHCLEAN $ GOTO FOURTHPAUSE $ FITHCLEAN: $ GOTO WIPESCN $ FITHLINE: $ WRITE SYS$OUTPUT "1 bottle of beer on the wall," $ C=0 $ L=6 $ FITHPAUSE: $ C=C+1 $ IF (C .EQ. 1200) THEN GOTO SIXTHCLEAN $ GOTO FITHPAUSE $ SIXTHCLEAN: $ GOTO WIPESCN $ SIXTHLINE: $ WRITE SYS$OUTPUT "1 bottle of beer..." $ C=0 $ L=7 $ SIXTHPAUSE: $ C=C+1 $ IF (C .EQ. 2200) THEN GOTO SEVENTHCLEAN $ GOTO SIXTHPAUSE $ SEVENTHCLEAN: $ GOTO WIPESCN $ SEVENTHLINE: $ WRITE SYS$OUTPUT "If it should happen to fall...." $ C=0 $ L=8 $ LASTPAUSE: $ C=C+1 $ IF (C .EQ. 2000) THEN GOTO LASTCLEAN $ GOTO LASTPAUSE $ LASTCLEAN: $ GOTO WIPESCN $ LASTLINE: $ WRITE SYS$OUTPUT "No more bottles of beer on the wall." $ GOTO QUIT $ WIPESCN: $ C=0 $ WIPE: $ C=C+1 $ WRITE SYS$OUTPUT " " $ IF (C .EQ. 25) THEN GOTO SONGLINE $ GOTO WIPE $ SONGLINE: $ IF (L .EQ. 1) THEN GOTO FIRSTLINE $ IF (L .EQ. 2) THEN GOTO SECONDLINE $ IF (L .EQ. 3) THEN GOTO THIRDLINE $ IF (L .EQ. 4) THEN GOTO FOURTHLINE $ IF (L .EQ. 5) THEN GOTO FITHLINE $ IF (L .EQ. 6) THEN GOTO SIXTHLINE $ IF (L .EQ. 7) THEN GOTO SEVENTHLINE $ IF (L .EQ. 8) THEN GOTO LASTLINE $ QUIT:
: TI-85 Printing calculator version of 99 Bottles of Beer PROGRAM:BEER :100-->A :2-->B :"Bottles of Beer"-->BOTTLES :"One Bottle of Beer"-->ONE :"On the Wall"-->ON :"Take one down"-->TAKE :"And pass it around."-->PASS :"Zero Bottles of Beer"-->ZERO :"Go to the store and "-->STORE :"Buy some more."-->BUY :Lbl LOOP :ClLCD :Outpt(1,1,A) :Outpt(1,5,BOTTLES) :Outpt(2,1,ON) :Outpt(3,1,A) :Outpt(3,5,BOTTLES) :Outpt(4,1,TAKE) :Outpt(5,1,PASS) :Outpt(6,1,A-1) :Outpt(6,5,BOTTLES) :DS<(A,F) :Pause :Goto LOOP :ClLCD :Outpt(1,1,ONE) :Outpt(2,1,ON) :Outpt(3,5,ONE) :Outpt(4,1,TAKE) :Outpt(5,1,PASS) :Outpt(6,1,ZERO) :Pause :ClLCD :Outpt(1,1,STORE) :Outpt(2,1,BUY) :Disp "" :Disp "Hit ENTER to buy more."
"Programmer: patrick m. ryan - pryan@access.digex.net
"http://www.access.digex.net/~pryan
99 to: 1 by: -1 do: [ :i |
i print. ' bottles of beer on the wall, ' print.
i print. ' bottles of beer. ' print.
'take one down, pass it around, ' print.
(i-1) print. ' bottles of beer on the wall, ' print.
]
C patrick m. ryan pryan@access.digex.net
program ninetynine
implicit none
integer i
do i=99,1,-1
print*, i,' bottles of beer on the wall, ',i,' bottles of beer'
print*, 'take one down, pass it around, ',i-1,
. ' bottles of beer on the wall'
enddo
end
(* Modula-2 version of 99 Bottles of Beer *)
(* Tested on a VAX 7700 running OpenVMS *)
(* Programmer: Jeremy Rule rulej@tempest.adsnet.net *)
MODULE BottlesOfBeer;
FROM InOut IMPORT WriteCard, WriteString, WriteLn;
CONST
BOTTLES = 99;
VAR
counter : CARDINAL;
BEGIN
counter := BOTTLES;
REPEAT
WriteCard( counter,2 );
WriteString(" bottles of beer on the wall, ");
WriteCard( counter,2 );
WriteString(" bottles of beer."); WriteLn;
WriteString(" Take one down, and pass it around, ");
DEC( counter );
WriteCard( counter,2 );
WriteString(" bottles of beer on the wall."); WriteLn;
UNTIL ( counter = 1 );
WriteString("1 bottle of beer on the wall, 1 bottle of beer"); WriteLn;
WriteString("Take it down and pass it around, ");
WriteString("No more bottles of beer on the wall."); WriteLn;
END BottlesOfBeer.
MODULE BottlesOfBeer EXPORTS Main;
FROM IO IMPORT Put ;
FROM Fmt IMPORT Int ;
VAR bottles := 99 ;
BEGIN
WHILE (bottles > 0) DO
Put(Int(bottles) & " bottle(s) of beer on the wall,\n") ;
Put(Int(bottles) & " bottle(s) of beer. \n") ;
Put("Take one down, and pass it around,\n");
DEC(bottles);
Put(Int(bottles) & " bottle(s) of beer on the wall.\n");
END ;
END BottlesOfBeer.
\ Forth version of the 99 Bottles program.
\ Dan Reish, dreish@umich.edu
: .bottles ( n -- n-1 )
dup 1 = IF ." One bottle of beer on the wall," CR
." One bottle of beer," CR
." Take it down,"
ELSE dup . ." bottles of beer on the wall," CR
dup . ." bottles of beer," CR
." Take one down,"
THEN
CR
." Pass it around," CR
1-
?dup IF dup 1 = IF ." One bottle of beer on the wall;"
ELSE dup . ." bottles of beer on the wall;"
THEN
ELSE ." No more bottles of beer on the wall."
THEN
CR
;
: nbottles ( n -- )
BEGIN .bottles ?dup NOT UNTIL
;
99 nbottles
#!/usr/bin/awk -f
# awk version of 99 bottles of beer
# by Whitey (whitey@netcom.com) - 06/05/95
BEGIN {
for(i = 99; i > 0; i--) {
print s = bottle(i), "on the wall,", s ","
print "take one down, pass it around,"
print bottle(i - 1), "on the wall."
}
}
function bottle(n) {
return sprintf("%s bottle%s of beer", n ? n : "no more", n - 1 ? "s" : "")
}
#!/usr/local/contrib/bin/python
# python version of 99 bottles of beer
# by Whitey (whitey@netcom.com) - 06/05/95
def bottle(n):
if n == 0:
return 'no more bottles of beer'
elif n == 1:
return '1 bottle of beer'
else:
return `n` + ' bottles of beer'
for i in range(99, 0, -1):
s = bottle(i)
print s, 'on the wall,', s + ','
print 'take one down, pass it around,'
print bottle(i - 1), 'on the wall.'
/* SAS version of 99 bottles of beer */
/* by Whitey (whitey@netcom.com) - 06/05/95 */
data _null_;
do i = 99 to 1 by -1;
put i 'bottles of beer on the wall,' i 'bottles of beer,';
put 'take one down, pass it around,';
j = i - 1;
if j = 0 then
put 'no more ' @;
else
put j @;
put 'bottles of beer on the wall.';
end;
run;
#! /usr/bin/perl
# Jim Menard jimm@{bbn,io}.com (617) 873-4326 http://www.io.com/~jimm/
$nBottles = $ARGV[0];
$nBottles = 100 if $nBottles eq '' || $nBottles < 0;
foreach (reverse(1 .. $nBottles)) {
$s = ($_ == 1) ? "" : "s";
$oneLessS = ($_ == 2) ? "" : "s";
print "\n$_ bottle$s of beer on the wall,\n";
print "$_ bottle$s of beer,\n";
print "Take one down, pass it around,\n";
print $_ - 1, " bottle$oneLessS of beer on the wall\n";
}
print "\n*burp*\n";
# Additional version: patrick m. ryan pryan@access.digex.net
C Allen Mcintosh
C mcintosh@bellcore.com
integer bottls
do 50 i = 1, 99
bottls = 100 - i
print 10, bottls
10 format(1x, i2, 31h bottle(s) of beer on the wall.)
print 20, bottls
20 format(1x, i2, 19h bottle(s) of beer.)
print 30
30 format(34h Take one down and pass it around,)
bottls = bottls - 1
print 10, bottls
print 40
40 format(1x)
50 continue
stop
end
%% TeX/LaTeX version of 99 bottles of Beer
%%
%% Craig J Copi - copi@oddjob.uchicago.edu
%%
\parindent=0pt
\newcount\beercurr
\def\beer#1{\beercurr=#1\let\next=\removebeer\removebeer}
\def\removebeer{
\ifnum\beercurr>1
\the\beercurr\ bottles of beer on the wall,\par
\the\beercurr\ bottles of beer,\par
take one down, pass it around,\par
\advance\beercurr by -1
\the\beercurr\ bottle\ifnum1<\beercurr{s}\fi\ of beer on the wall.\par
\vskip 2ex\relax
\else
1 bottle of beer on the wall,\par 1 bottle of beer,\par
take one down, pass it around,\par no bottles of beer on the wall.\par
\vskip .5ex
Time to buy some more beer\ldots. \let\next=\relax
\fi
\next}
\beer{99}
#!/bin/sh
# Bourne shell version of 99 Bottles
# Craig J Copi - copi@oddjob.uchicago.edu
#
if [ $# -eq 1 ]; then
beers=$1
else
beers=99
fi
s="s"
while [ $beers -gt 0 ]; do
echo "$beers bottle$s of beer on the wall,"
echo "$beers bottle$s of beer,"
echo "take one down, pass it around,"
beers=`expr $beers - 1`
if [ $beers -ne 0 ]; then
test $beers -eq 1 && s=""
echo "$beers bottle$s of beer on the wall."
else
echo "no bottles of beer on the wall."
fi
echo
done
echo
echo "Time to buy some more beer . . . ."
;;;Common Lisp using IBUKI ;;;Author: Patrick Amato, 1995 - amato@umiacs.UMD.EDU ;;;http://www.umiacs.umd.edu/staff/amato/amato.html ;;;In the spirit of lisp I made this recursive. (setf *num_bottles* 99) (defun 99_bottles(cnt) (if (> cnt 0) (or (format t "~& ~S Bottle(s) of beer on the wall," cnt) (format t "~& Take one down and pass it around,") (99_bottles (- cnt 1))) T)); (99_bottles *num_bottles*);
;;Geza Gyuk - gyuk@oddjob.uchicago.edu"
(defun beersong (n)
"Does the n-beers song."
(progn (insert (int-to-string n) " bottle" (cond ((= n 1) "")
(t "s"))
" of beer on the wall,\n")
(insert (int-to-string n) " bottle" (cond ((= n 1) "")
(t "s"))
" of beer,\n")
(insert "take one down and pass it around,\n")
(insert (cond ((= n 1) "no more")
(t (int-to-string (- n 1))))
" bottle" (cond ((= n 2) "")
(t "s"))
" of beer on the wall.\n\n")
(cond ((> n 1) (beersong (- n 1))))))
*--- Chris Lopez - lopez@huey.vp.uiuc.edu ---*
*--- start of code ---*
define
maxbeer = 99
origin:n1
beer $$ # of beers remaining
atloc $$ where to start writing this line
nextlin(x) = (x <= (x+100) $mod$ 3200)
*
mode rewrite
calc beer <= maxbeer
atloc <= 1
loop
. at nextlin(atloc)
. showt beer,2
. * Warning: trailing space on following line
. write bottles of beer on the wall,
. showt beer,2
. write bottles of beer.
. at nextlin(atloc)
. write Take one down, pass it around.
outloop ((beer<=beer-1) < 2)
. showt beer-1,2
. write bottles of beer.
endloop
*
write 1 bottle of beer.
at nextlin(atloc)
write 1 Bottle of beer on the wall, 1 bottle of beer.
Take it down, pass it around, no bottles of beer on the wall.
*
pause keys=all
jumpout q
*--- end of code ---*
/*
99 bottles of beer in Prolog
Rob van de Pol
R.vandePol@voeding.tno.nl
TNO Nutrition and Food Research Institute
The Netherlands
*/
domains
count = integer
predicates
bottles(count)
clauses
bottles(1) :-
write ("1 bottle of beer on the wall, 1 bottle of beer,\n"),
write ("Take one down, and pass it around,\n"),
write ("Now they are alle gone.").
bottles(X) :-
write ( X , " bottles of beer on the wall, " ,
X , " bottles of beer,\n"),
write ("Take one down, and pass it around,\n"),
X1 = X - 1,
write ( X1 , " bottles of beer on the wall.\n",
bottles(X1).
goal
bottles(99)
// beersong.c
// an implementation in the LPC language
// Tim Hollebeek, 6/6/95 - tim@debusy.Princeton.EDU
private string bottles(int n) {
switch (n) {
case 0: return "no more bottles of beer";
case 1: return "1 bottle of beer";
default: return n + " bottles of beer";
}
}
void beersong() {
for (int i = 99; i; i--) {
write(bottles(i) + " on the wall, " + bottles(i)
+ ", take one down, pass it around, "
+ bottles(i - 1) + " on the wall.\n");
}
}
! Does the beer song... sends output to a postscript file
! Geza Gyuk - gyuk@oddjob.uchicago.edu
printer 1
erase
data beer.dat
setv rounds c1(1) ! get number of rounds
! from first line, first
setv container bottles ! column of file beer.dat
expand {5/rounds}
loop i {rounds} 2 -1
relocate 0.1 {i*5/(5*rounds)}
putlabel 6 {i} bottles of beer on the wall,
relocate 0.1 {(i*5-1)/(5*rounds)}
putlabel 6 {i} bottles of beer,
relocate 0.1 {(i*5-2)/(5*rounds)}
putlabel 6 take one down and pass it around,
if ({i}=2) setv container bottle
relocate 0.1 {(i*5-3)/(5*rounds)}
putlabel 6 {i-1} {container} of beer on the wall.
relocate 0.1 {(i*5-4)/(5*rounds)}
putlabel 6
endloop
relocate 0.1 {5/(5*rounds)}
putlabel 6 1 bottle of beer on the wall,
relocate 0.1 {4/(5*rounds)}
putlabel 6 1 bottle of beer,
relocate 0.1 {3/(5*rounds)}
putlabel 6 take it down and pass it around,
relocate 0.1 {2/(5*rounds)}
putlabel 6 no more bottles of beer on the wall.
hardcopy
end
; The following is a single line of code
beer ; Randy M. Hayman (haymanr@icefog.alaska.edu)
for i=99:-1:1 w !,i," bottle",$S(i=1:"",1:"s")," of beer on the wa
ll, ",i," bottle",$S(i=1:"",1:"s")," of beer.",!,"Take one down, pass it a
round, ",i-1," bottle",$S(i=2:"",1:"s")," of beer on the wall.",!
# Tcl version of 99 bottles of beer on the wall
# Author: Don Libes (libes@nist.gov)
#
proc bottles {i} {
return "$i bottle[expr $i!=1?"s":""] of beer"
}
proc line123 {i} {
puts "[bottles $i] on the wall,"
puts "[bottles $i],"
puts "take one down, pass it around,"
}
proc line4 {i} {
puts "[bottles $i] on the wall.\n"
}
for {set i 99} {$i>0} {} {
line123 $i
incr i -1
line4 $i
}
#!/usr/local/bin/itcl_sh
# [incr Tcl] version of "99 bottles of beer"
# Author: Steven Grady
# grady@xcf.berkeley.edu
itcl_class bottle {
constructor {config} {
incr numBottles
}
destructor {
incr numBottles -1
}
method drink {} {
puts "Take one down, pass it around,"
$this delete
}
proc numBottleStr {} {
switch $numBottles {
0 {
return "No more bottles of beer"
}
1 {
return "1 bottle of beer"
}
default {
return "$numBottles bottles of beer"
}
}
}
proc numBottles {} {
return $numBottles
}
common numBottles 0
}
proc createBottles {numBottles} {
for {set i 0} {$i < $numBottles} {incr i} {
bottle #auto
}
}
createBottles 99
foreach b [itcl_info objects -class bottle] {
set str [bottle :: numBottleStr]
puts "$str on the wall, $str"
$b drink
puts "[bottle :: numBottleStr] on the wall."
}
(* SML version of 99 bottles of beer *)
(* written by Norvald - norvald@hsr.no *)
let
val itoa = Makestring.intToStr
fun getabeer 0 = (print "Go to the store and buy some more,\n";
print "99 bottles of beer on the wall.\n")
| getabeer 1 = (print "1 bottle of beer on the wall,\n";
print "1 bottle of beer,\n";
print "Take one down, pass it around,\n";
print "0 bottle of beer on the wall.\n\n";
getabeer (0))
| getabeer x = (print (itoa(x)^" bottles of beer on the wall,\n");
print (itoa(x)^" bottles of beer,\n");
print "Take one down, pass it around,\n";
print (itoa(x-1)^" bottles of beer on the wall.\n\n");
getabeer (x-1))
in
getabeer 99;
end
remark 99 bottles of beer with Oracle SQL*Plus
remark R.vandePol@voeding.tno.nl < Rob van de Pol>
remark
remark assuming that YourTable contains at least 99 rows ;-)
remark
remark RowNum is an Oracle psuedo column indicating the sequence the rows
remark were selected.
SELECT TO_CHAR(100-rownum)||' bottles of beer on the wall, ' ||
TO_CHAR(100-rownum)||' bottles of beer,' ,
'take one down and pass it around, ' ,
DECODE ( TO_CHAR(99-rownum) , '0' , 'No more' , TO_CHAR(99-rownum) )||
' bottles of beer,'
FROM YourTable
WHERE rownum < 100
# Mike Romberg (romberg@md.fsl.noaa.gov) # define(`forloop', `pushdef(`$1', `$2')_forloop(`$1', `$2', `$3', `$4')popdef(`$1')') define(`_forloop', `$4`'ifelse($1, `$3', , `define(`$1', decr($1)) _forloop(`$1', `$2', `$3', `$4')')') define(`Bottles', `ifelse($1, `0', `No bottles', `ifelse($1, `1', `$1 bottle', `$1 bottles')')') define(`OBOTW', `of beer on the wall') define(`S1', `Bottles(i) OBOTW') define(`S2', `Bottles(i) OBOTW Bottles(i) of beer') define(`S3', `Take one down and pass it around S4($1) ') define(`S4', `Bottles(decr(i)) OBOTW') define(`S5', `S2(i) S3(i) ') forloop(`i', 99, 1, `S5(i)')
;;; Tim Goodwin (tim@pipex.net)
(define bottles
(lambda (n)
(cond ((= n 0) (display "No more bottles"))
((= n 1) (display "One bottle"))
(else (display n) (display " bottles")))
(display " of beer")))
(define beer
(lambda (n)
(if (> n 0)
(begin
(bottles n) (display " on the wall") (newline)
(bottles n) (newline)
(display "Take one down, pass it around") (newline)
(bottles (- n 1)) (display " on the wall") (newline)
(newline)
(beer (- n 1))))))
(beer 99)
.\" Tim Goodwin.nr BO 99 .de BP .if \\n(BO=0 No more .if !\\n(BO=0 \\n(BO .if \\n(BO=1 bottle .if !\\n(BO=1 bottles of beer .. .de WP .BP on the wall .. .de BE .WP .br .BP .br Take one down, pass it around .br .nr BO \\n(BO-1 .WP .sp .if \\n(BO>0 .BE .. .BE
{----------------------------------------------------------------------}
{Contents of BEER99.DPR}
program Beer99;
{99 bottles of beer - Borland Delphi 1.0}
{by Rodney M. Savard }
uses
Forms,
Beer in 'BEER.PAS' {Form1};
{$R *.RES}
begin
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
{----------------------------------------------------------------------}
{Contents of BEER.PAS}
unit Beer;
interface
uses
Classes, Controls, Forms, StdCtrls, SysUtils;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Bottles: Integer;
s: String;
implementation
{$R *.DFM}
procedure TakeOneDown;
begin
with Form1 do begin
Memo1.Lines.Clear;
Memo1.Lines.Add(IntToStr(bottles)+' bottle'+s+' of beer on the wall,');
Memo1.Lines.Add(IntToStr(bottles)+' bottle'+s+' of beer.');
Memo1.Lines.Add('');
Memo1.Lines.Add('Take one down, pass it around,');
Dec(Bottles);
if Bottles<>1 then s:='s' else s:='';
if Bottles=0 then begin
Memo1.Lines.Add('no more bottles of beer on the wall!');
Button1.Caption:='No More!';
Button1.Enabled:=False;
end
else begin
Memo1.Lines.Add(IntToStr(bottles)+' bottle'+s+' of beer on the wall.');
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Bottles:=99;
s:='s';
Button1Click(Form1);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TakeOneDown;
end;
end.
{----------------------------------------------------------------------}
@ECHO OFF :: BEER.BTM - 4DOS version 5.5 batch (btm) file :: by Rodney M. SavardSETLOCAL SET plural=`s` DO bottle = 99 TO 1 BY -1 ECHOS %bottle% bottle%plural% of beer on the wall, ECHO %bottle% bottle%plural% of beer. ECHOS Take one down, pass it around, IFF (%@EVAL[%bottle% - 1]) == (0) THEN ECHO no more bottles of beer on the wall. ELSE IF (%@EVAL[%bottle% - 1]) == (1) UNSET plural ECHO %@EVAL[%bottle% - 1] bottle%plural% of beer on the wall. ECHO. ENDIFF ENDDO ENDLOCAL
/* AML (Arc Macro Language) version of 99 bottles of beer on the wall
/* Author prefers anonymity B-)
/*
&do number = 9 &to 1 &by -1
/* handle the one bottle cases
&if %number% = 1 &then
&set noun1 = bottle
&else
&set noun1 = bottles
&if %number% = 2 &then
&set noun2 = bottle
&else
&set noun2 = bottles
&type \%number% %noun1% of beer on the wall,
&type %number% %noun1% of beer,
&type Take one down, pass it around,
&type [calc %number% - 1] %noun2% of beer on the wall
&end
&return
/***********************************************************
* Module: 99 bottles of beer
* By Danny Mulligan
***********************************************************/
module beer;
integer i;
initial begin
for (i=99; i>0; i=i-1)
begin
$display("%0d bottles of beer on the wall,", i);
$display("%0d bottles of beer,", i);
$display("Take one down and pass it around,");
if (i==1)
$display("No more bottles of beer on the wall.\n");
else
$display("%0d bottles of beer on the wall.\n", i-1);
end
$display("Go to the store and buy some more.");
end
end
// java version of 99 bottles of beer on the wall
// 1995 Sean Russell (ser@cs.uoregon.edu)
class bottles
{
public static void main(String args[])
{
String s = "s";
for (int beers=99; beers>-1;)
{
System.out.print(beers + " bottle" + s + " of beer on the wall, ");
System.out.println(beers + " bottle" + s + " of beer, ");
if (beers==0)
{
System.out.print("Go to the store, buy some more, ");
System.out.println("99 bottles of beer on the wall.\n");
System.exit(0);
}
else
System.out.print("Take one down, pass it around, ");
s = (--beers == 1)?"":"s";
System.out.println(beers + " bottle" + s + " of beer on the wall.\n");
}
}
}
TITLE 'More Beer - By Gary Bergman'
BALR 6,0
USING *,6
OPEN PRINT
LA 5,99
SHOWBEER MVC MSGAREA(L'BEERMSG),BEERMSG
PUT PRINT,MSGAREA '...wall,'
MVC MSGAREA+18(12),=CL12'.'
PUT PRINT,MSGAREA '...wall.'
PUT PRINT,TAKEMSG 'take one'
BCT 5,MOREBEER
MVC MSGAREA(7),=C'No more'
MVC MSGAREA+7(L'BEERMSG-4),BEERMSG+4
PUT PRINT,MSGAREA
PUT PRINT,LASTMSG
CLOSE PRINT
SVC EOJ
*
MOREBEER CVD 5,DWORD set new count
MVC BEERMSG(4),=X'40202021' edit pattern
ED BEERMSG(4),DWORD+6(2) display numb
MVC MSGAREA(L'BEERMSG),BEERMSG
MVI MSGAREA+L'BEERMSG-1,C'.'
PUT PRINT,MSGAREA
MVI MSGAREA+L'BEERMSG-1,C','
B SHOWBEER
DWORD DS D
MSGAREA DC 80C' '
BEERMSG DC C' 99 bottles of beer on the wall,'
TAKEMSG DC CL80'Take one down, Pass it around.'
LASTMSG DC CL80'Go to the store and buy some more.'
PLEASE DO ,10 <- #1
PLEASE DO ,10SUB#1 <- #176
PLEASE DO ,11 <- #30
PLEASE DO ,11SUB#1 <- #76
DO ,11SUB#2 <- #190
DO ,11SUB#3 <- #80
DO ,11SUB#4 <- #200
PLEASE DO ,11SUB#5 <- #256
DO ,11SUB#6 <- #248
DO ,11SUB#7 <- #144
DO ,11SUB#8 <- #216
PLEASE DO ,11SUB#9 <- #202
DO ,11SUB#10 <- #14
DO ,11SUB#11 <- #144
DO ,11SUB#12 <- #98
PLEASE DO ,11SUB#13 <- #190
DO ,11SUB#14 <- #160
DO ,11SUB#15 <- #256
DO ,11SUB#16 <- #88
PLEASE DO ,11SUB#17 <- #74
DO ,11SUB#18 <- #14
DO ,11SUB#19 <- #128
DO ,11SUB#20 <- #114
PLEASE DO ,11SUB#21 <- #214
DO ,11SUB#22 <- #24
DO ,11SUB#23 <- #112
DO ,11SUB#24 <- #162
PLEASE DO ,11SUB#25 <- #22
DO ,11SUB#26 <- #104
DO ,11SUB#27 <- #80
DO ,11SUB#28 <- #256
PLEASE DO ,11SUB#29 <- #2
DO ,11SUB#30 <- #228
PLEASE DO ,12 <- #49
PLEASE DO ,12SUB#1 <- #76
DO ,12SUB#2 <- #190
DO ,12SUB#3 <- #80
DO ,12SUB#4 <- #200
PLEASE DO ,12SUB#5 <- #256
DO ,12SUB#6 <- #248
DO ,12SUB#7 <- #144
DO ,12SUB#8 <- #216
PLEASE DO ,12SUB#9 <- #202
DO ,12SUB#10 <- #14
DO ,12SUB#11 <- #144
DO ,12SUB#12 <- #98
PLEASE DO ,12SUB#13 <- #190
DO ,12SUB#14 <- #160
DO ,12SUB#15 <- #256
DO ,12SUB#16 <- #88
PLEASE DO ,12SUB#17 <- #218
DO ,12SUB#18 <- #36
DO ,12SUB#19 <- #38
DO ,12SUB#20 <- #164
PLEASE DO ,12SUB#21 <- #176
DO ,12SUB#22 <- #48
DO ,12SUB#23 <- #162
DO ,12SUB#24 <- #14
PLEASE DO ,12SUB#25 <- #128
DO ,12SUB#26 <- #208
DO ,12SUB#27 <- #162
DO ,12SUB#28 <- #222
PLEASE DO ,12SUB#29 <- #48
DO ,12SUB#30 <- #8
DO ,12SUB#31 <- #120
DO ,12SUB#32 <- #66
PLEASE DO ,12SUB#33 <- #48
DO ,12SUB#34 <- #246
DO ,12SUB#35 <- #136
DO ,12SUB#36 <- #184
PLEASE DO ,12SUB#37 <- #256
DO ,12SUB#38 <- #202
DO ,12SUB#39 <- #110
DO ,12SUB#40 <- #104
PLEASE DO ,12SUB#41 <- #42
DO ,12SUB#42 <- #126
DO ,12SUB#43 <- #56
DO ,12SUB#44 <- #88
PLEASE DO ,12SUB#45 <- #72
DO ,12SUB#46 <- #56
DO ,12SUB#47 <- #80
DO ,12SUB#48 <- #242
PLEASE DO ,12SUB#49 <- #228
PLEASE DO ,13 <- #31
PLEASE DO ,13SUB#1 <- #76
DO ,13SUB#2 <- #190
DO ,13SUB#3 <- #80
DO ,13SUB#4 <- #200
PLEASE DO ,13SUB#5 <- #256
DO ,13SUB#6 <- #248
DO ,13SUB#7 <- #144
DO ,13SUB#8 <- #216
PLEASE DO ,13SUB#9 <- #202
DO ,13SUB#10 <- #14
DO ,13SUB#11 <- #144
DO ,13SUB#12 <- #98
PLEASE DO ,13SUB#13 <- #190
DO ,13SUB#14 <- #160
DO ,13SUB#15 <- #256
DO ,13SUB#16 <- #88
PLEASE DO ,13SUB#17 <- #74
DO ,13SUB#18 <- #14
DO ,13SUB#19 <- #128
DO ,13SUB#20 <- #114
PLEASE DO ,13SUB#21 <- #214
DO ,13SUB#22 <- #24
DO ,13SUB#23 <- #112
DO ,13SUB#24 <- #162
PLEASE DO ,13SUB#25 <- #22
DO ,13SUB#26 <- #104
DO ,13SUB#27 <- #80
DO ,13SUB#28 <- #256
PLEASE DO ,13SUB#29 <- #194
DO ,13SUB#30 <- #36
DO ,13SUB#31 <- #256
PLEASE DO ,20 <- #10
PLEASE DO ,20 SUB #1 <- #76
DO ,20 SUB #2 <- #196
DO ,20 SUB #3 <- #4
DO ,20 SUB #4 <- #132
PLEASE DO ,20 SUB #5 <- #36
DO ,20 SUB #6 <- #164
DO ,20 SUB #7 <- #228
DO ,20 SUB #8 <- #100
PLEASE DO ,20 SUB #9 <- #52
DO ,20 SUB #10 <- #180
PLEASE DO ,21 <- #10 BY #10
PLEASE DO ,21SUB#1#1 <- #248
PLEASE DO ,21SUB#1#2 <- #120
PLEASE DO ,21SUB#1#3 <- #184
PLEASE DO ,21SUB#1#4 <- #56
PLEASE DO ,21SUB#1#5 <- #216
PLEASE DO ,21SUB#1#6 <- #88
PLEASE DO ,21SUB#1#7 <- #152
PLEASE DO ,21SUB#1#8 <- #24
PLEASE DO ,21SUB#1#9 <- #232
PLEASE DO ,21SUB#1#10 <- #104
DO ,21SUB#2#1 <- #128
DO ,21SUB#2#2 <- #256
DO ,21SUB#2#3 <- #64
DO ,21SUB#2#4 <- #192
DO ,21SUB#2#5 <- #96
DO ,21SUB#2#6 <- #224
DO ,21SUB#2#7 <- #32
DO ,21SUB#2#8 <- #160
DO ,21SUB#2#9 <- #112
DO ,21SUB#2#10 <- #240
DO ,21SUB#3#1 <- #64
DO ,21SUB#3#2 <- #192
DO ,21SUB#3#3 <- #256
DO ,21SUB#3#4 <- #128
DO ,21SUB#3#5 <- #32
DO ,21SUB#3#6 <- #160
DO ,21SUB#3#7 <- #224
DO ,21SUB#3#8 <- #96
DO ,21SUB#3#9 <- #48
DO ,21SUB#3#10 <- #176
DO ,21SUB#4#1 <- #192
DO ,21SUB#4#2 <- #64
DO ,21SUB#4#3 <- #128
DO ,21SUB#4#4 <- #256
DO ,21SUB#4#5 <- #160
DO ,21SUB#4#6 <- #32
DO ,21SUB#4#7 <- #96
DO ,21SUB#4#8 <- #224
DO ,21SUB#4#9 <- #176
DO ,21SUB#4#10 <- #48
PLEASE DO ,21SUB#5#1 <- #32
PLEASE DO ,21SUB#5#2 <- #160
PLEASE DO ,21SUB#5#3 <- #224
PLEASE DO ,21SUB#5#4 <- #96
PLEASE DO ,21SUB#5#5 <- #256
PLEASE DO ,21SUB#5#6 <- #128
PLEASE DO ,21SUB#5#7 <- #192
PLEASE DO ,21SUB#5#8 <- #64
PLEASE DO ,21SUB#5#9 <- #16
PLEASE DO ,21SUB#5#10 <- #144
DO ,21SUB#6#1 <- #160
DO ,21SUB#6#2 <- #32
DO ,21SUB#6#3 <- #96
DO ,21SUB#6#4 <- #224
DO ,21SUB#6#5 <- #128
DO ,21SUB#6#6 <- #256
DO ,21SUB#6#7 <- #64
DO ,21SUB#6#8 <- #192
DO ,21SUB#6#9 <- #144
DO ,21SUB#6#10 <- #16
DO ,21SUB#7#1 <- #96
DO ,21SUB#7#2 <- #224
DO ,21SUB#7#3 <- #32
DO ,21SUB#7#4 <- #160
DO ,21SUB#7#5 <- #64
DO ,21SUB#7#6 <- #192
DO ,21SUB#7#7 <- #256
DO ,21SUB#7#8 <- #128
DO ,21SUB#7#9 <- #80
DO ,21SUB#7#10 <- #208
DO ,21SUB#8#1 <- #224
DO ,21SUB#8#2 <- #96
DO ,21SUB#8#3 <- #160
DO ,21SUB#8#4 <- #32
DO ,21SUB#8#5 <- #192
DO ,21SUB#8#6 <- #64
DO ,21SUB#8#7 <- #128
DO ,21SUB#8#8 <- #256
DO ,21SUB#8#9 <- #208
DO ,21SUB#8#10 <- #80
PLEASE DO ,21SUB#9#1 <- #16
PLEASE DO ,21SUB#9#2 <- #144
PLEASE DO ,21SUB#9#3 <- #208
PLEASE DO ,21SUB#9#4 <- #80
PLEASE DO ,21SUB#9#5 <- #240
PLEASE DO ,21SUB#9#6 <- #112
PLEASE DO ,21SUB#9#7 <- #176
PLEASE DO ,21SUB#9#8 <- #48
PLEASE DO ,21SUB#9#9 <- #256
PLEASE DO ,21SUB#9#10 <- #128
DO ,21SUB#10#1 <- #144
DO ,21SUB#10#2 <- #16
DO ,21SUB#10#3 <- #80
DO ,21SUB#10#4 <- #208
DO ,21SUB#10#5 <- #112
DO ,21SUB#10#6 <- #240
DO ,21SUB#10#7 <- #48
DO ,21SUB#10#8 <- #176
DO ,21SUB#10#9 <- #128
DO ,21SUB#10#10 <- #256
PLEASE DO ,22 <- #10
PLEASE DO ,22 SUB #1 <- #8
DO ,22 SUB #2 <- #136
DO ,22 SUB #3 <- #72
DO ,22 SUB #4 <- #200
PLEASE DO ,22 SUB #5 <- #40
DO ,22 SUB #6 <- #168
DO ,22 SUB #7 <- #104
DO ,22 SUB #8 <- #232
PLEASE DO ,22 SUB #9 <- #24
DO ,22 SUB #10 <- #152
DO .10 <- #9
DO .11 <- #9
PLEASE DO ,10 <- #1
PLEASE DO ,10SUB#1 <- #176
DO READ OUT ,10
DO COME FROM (999)
DO (500) NEXT
PLEASE DO ,11SUB#1 <- .5
DO READ OUT ,11
DO (500) NEXT
DO ,12SUB#1 <- .5
PLEASE DO READ OUT ,12
PLEASE DO .6 <- '?"!10~.10'~#1"$#1'~#3
DO (50) NEXT
PLEASE DO .7 <- '?"!11~.11'~#1"$#1'~#3
DO (70) NEXT
DO .2 <- #1
DO .1 <- .11
PLEASE DO (1010) NEXT
DO .11 <- .3
DO (600) NEXT
DO (101) NEXT
(70) DO (71) NEXT
DO .11 <- #9
DO .2 <- #1
PLEASE DO .1 <- .10
DO (1010) NEXT
DO .10 <- .3
DO (600) NEXT
DO (101) NEXT
(71) DO RESUME .7
(50) DO (51) NEXT
PLEASE DO FORGET #1
DO .2 <- #1
DO .1 <- .11
PLEASE DO (1010) NEXT
DO .11 <- .3
DO (600) NEXT
PLEASE DO .7 <- '?"!11~.11'~#1"$#1'~#3
DO (80) NEXT
DO (101) NEXT
(80) DO (81) NEXT
DO GIVE UP
(81) DO RESUME .7
(51) DO RESUME .6
(101) DO FORGET #1
(999) DO FORGET #1
(600) DO (500) NEXT
DO ,13SUB#1 <- .5
DO READ OUT ,13
DO RESUME #1
(500) DO ,30 <- #1
DO .1 <- .10
DO (1020) NEXT
PLEASE DO ,30SUB#1 <- ,20SUB.1
DO READ OUT ,30
DO .3 <- .1
DO .1 <- .11
DO (1020) NEXT
PLEASE DO ,30SUB#1 <- ,21SUB .3 .1
DO READ OUT ,30
DO .5 <- ,22SUB.1
PLEASE DO RESUME #1
// Dylan version of 99 Bottles of Beer // programmer: Jim Studt jim@federated.com define method enumerate( count == 1 ) "1 bottle" end method enumerate; define method enumerate( count == 0 ) "no more bottles" end method enumerate; define method enumerate( count ::; ) format-to-string("%d bottles", count); end method enumerate; define method reference( count == 1) "it" end method reference; define method reference( count :: ) "one" end method reference; define method main (argv0, #rest noise) for ( i from 99 to 1 by -1) format( *standard-output*, "%s of beer on the wall, %s of beer.\n", enumerate(i), enumerate(i)); format( *standard-output*, " Take %s down, pass it around, %s of beer on the wall.\n", reference(i), enumerate( i - 1)); end for; end method main;
MODULE BottlesOfBeers; (* Andrejs Jansons 27.10.95 *)
IMPORT Out;
PROCEDURE Start*;
VAR
bottles: INTEGER;
BEGIN
bottles := 99;
REPEAT
Out.Int(bottles, 2);
Out.String(" bottles of beer on the wall, ");
Out.Int(bottles, 2);
Out.String(" bottles of beer.");
Out.Ln;
Out.String("Take one down, pass it around, ");
DEC(bottles);
Out.Int(bottles, 2);
Out.String(" bottles of beer on the wall.");
Out.Ln
UNTIL bottles = 1;
Out.String("1 bottle of beer on the wall, one bottle of beer.");
Out.Ln;
Out.String("Take one down, pass it around,");
Out.String(" no more bottles of beer on the wall");
Out.Ln
END Start;
END BottlesOfBeers.
This is a noteworty Object Oriented version in Oberon:
MODULE BeerSong;
(* An object-oriented beer song in Oberon-2 *)
(* Contributed by Michael Griebling (mgriebling@bix.com) *)
IMPORT O:=Out;
TYPE
WallObject* = RECORD beer-: SHORTINT END;
VAR
BeerWall : WallObject;
PROCEDURE (VAR wall: WallObject) LineEmUp*;
BEGIN wall.beer := 99
END LineEmUp;
PROCEDURE (VAR wall: WallObject) PassOneAround*;
BEGIN DEC(wall.beer)
END PassOneAround;
PROCEDURE (VAR wall: WallObject) HasMoreBeer* () : BOOLEAN;
BEGIN RETURN wall.beer > 0
END HasMoreBeer;
PROCEDURE SingOf(beer: SHORTINT);
BEGIN
IF beer = 0 THEN O.String("No more") ELSE O.Int(beer, 1) END;
O.String(" bottle"); IF beer#1 THEN O.Char("s") END; O.String(" of beer")
END SingOf;
PROCEDURE (VAR wall: WallObject) SingVerse*;
BEGIN
SingOf(wall.beer); O.String(" on the wall, "); SingOf(wall.beer); O.Ln;
O.String("Take one down and pass it around,"); O.Ln;
SingOf(wall.beer-1); O.String(" on the wall."); O.Ln; O.Ln
END SingVerse;
BEGIN
BeerWall.LineEmUp;
WHILE BeerWall.HasMoreBeer() DO BeerWall.SingVerse; BeerWall.PassOneAround END
END BeerSong.
BEGIN
COMMENT
Simula version of 99 beers
Maciej Macowicz (mm@cpe.ipl.fr)
Status: UNTESTED :)
;
INTEGER bottles;
FOR bottles:= 99 STEP -1 UNTIL 1 DO
BEGIN
OutInt(bottles,1);
OutText("bottle(s) of beer on the wall, ");
OutInt(bottles,1);
Outtext("bottle(s) of beer");
OutImage;
Outtext("Take one down, pass it around, ");
OutInt(bottles,1);
OutText("bottle(s) of beer on the wall, ");
END;
OutText("1 bottle of beer on the wall, one bottle of beer.");
Outimage;
OutText("Take one down, pass it around, no more bottles of beer on the wall");
OutImage
END
ORIGIN '~beta/basiclib/v1.4/betaenv';
--- program: descriptor ---
(* 99 bottles in BETA. Ole Villumsen, October 27, 1995. *)
(# putBottles: (# no: @integer;
enter no
do (if no//1 then '1 bottle' -> putLine;
else no -> putInt; ' bottles' -> putText;
if);
#);
do (for i:99 repeat
100-i -> putBottles; ' of beer on the wall,' -> putLine;
100-i -> putBottles; ' of beer.' -> putLine;
'Take one down, pass it around,' -> putLine;
99-1 -> putBottles; ' of beer on the wall.' -> putLine; newLine;
for)
#)
/* Tim Nason, 27 Oct 95 */
procedure beer
local nBeers := 99
while .t.
?
? alltrim( str( nBeers ) ) + ' bottle' + iif( nBeers = 1, '', 's' ) + ;
' of beer on the wall.'
? alltrim( str( nBeers ) ) + ' bottle' + iif( nBeers-- = 1, '', 's' ) + ;
' of beer.'
if nBeers < 0
? "Go to the store and buy some more."
nBeers := 99
? '99 bottles of beer on the wall.'
else
? 'Take one down, pass it around,'
? alltrim( str( nBeers ) ) + ' bottles of beer on the wall.'
endif
enddo
return
-- Sather for 99 Bottles of Beer
--
-- David Stoutamire (davids@icsi.berkeley.edu)
class MAIN is
main is
loop
b::=99.downto!(1);
#OUT + bob(b) + " on the wall, "
+ bob(b) + ".\n"
+ "Take one down, pass it around, "
+ bob(b-1) + " on the wall.\n\n";
end
end;
bob(i:INT):STR is
case i
when 0 then return "no more bottles of beer";
when 1 then return "1 bottle of beer";
else return i.str + " bottles of beer";
end
end
end
class BEERS
creation
make
feature -- Creation
make is
local
i : INTEGER
b : STRING;
do
from i := 99 variant i until i <= 0 loop
if i = 1 then
b := " bottle";
else
b := " bottles"
end -- if
io.put_integer(i);
io.put_string(b);
io.put_string(" of beer on the wall, ");
io.put_integer(i);
io.put_string(b);
io.put_string(" of beer,");
io.new_line;
io.put_string("Take one down and pass it around, ");
i := i - 1;
io.put_integer(i);
io.put_string(b);
io.put_string(" bottles of beer on the wall.");
io.new_line;
end -- loop
io.put_string("Go to the store and buy some more,");
io.new_line;
io.put_string("99 bottles of beer on the wall.");
io.new_line;
end;
end -- class BEERS
BEGIN
FILE TERM(KIND=REMOTE,MYUSE=OUT);
EBCDIC ARRAY OUTLINE[0:72];
PROCEDURE BOTTLECOUNT(I,P);
VALUE I; INTEGER I;
POINTER P;
BEGIN
REPLACE P:P BY I FOR * DIGITS, " bottle",
IF I NEQ 1 THEN "s " ELSE " ";
END;
POINTER OP;
INTEGER BOTTLES;
BOTTLES := 99;
FOR BOTTLES := 99 STEP -1 UNTIL 1 DO BEGIN
OP := OUTLINE;
BOTTLECOUNT(BOTTLES,OP);
REPLACE OP:OP BY "of beer on the wall,";
WRITE(TERM,,OUTLINE);
OP := OUTLINE;
BOTTLECOUNT(BOTTLES,OP);
REPLACE OP:OP BY "of beer,";
WRITE(TERM,,OUTLINE);
WRITE(TERM,<"You take one down and pass it around,">);
OP := OUTLINE;
BOTTLECOUNT(BOTTLES-1,OP);
REPLACE OP:OP BY "of beer on the wall.";
WRITE(TERM,,OUTLINE);
END FOR;
END.
-- This is the VHDL (ANSI/IEEE Std 1076 - 1993)
-- version of the beer song.
-- F. J. Ludicky, Sundstrand Aerospace
entity beer_song is
port(bottles: out integer;
words: out string(1 to 28);
start_singing: in boolean);
end beer_song;
architecture silly of beer_song is
begin
lets_sing: process
begin
wait on start_singing until start singing;
for index_bottles in 99 downto 1 loop
bottles <= index_bottles;
words <= "bottles of beer on the wall,";
wait for 5 sec;
bottles <= index_bottles;
words <= "bottles of beer, ";
wait for 5 sec;
words <= "take one down, ";
wait for 5 sec;
words <= "pass it around, ";
wait for 5 sec;
bottles <= index_bottles - 1;
words <= "bottles of beer on the wall."
wait for 5 sec.
end loop;
assert false report "No more beer!" severity warning;
end process lets_sing;
end silly;
# Scott E Gilbertprocedure main() t:= table("bottles") t[1]:= "bottle" every n:= 100 to 1 by -1 do { write(n, " ", t[n], " of beer on the wall.\n", n, " ", t[n], " of beer.\n", "Take one down, Pass it around.\n", n-1, " ", t[n-1], " of beer on the wall.\n" ) } end
-- AppleScript version of "99 Bottles of Beer"
-- by Kristopher Johnson kdj@mindspring.com
to createBottleString for aNumberOfBottles
if aNumberOfBottles is 0 then
return "No more bottles"
else if aNumberOfBottles is 1 then
return "1 more bottle"
else
return (aNumberOfBottles as string) & " bottles"
end if
end createBottleString
set lyrics to ""
repeat with numberOfBottles from 99 to 1 by -1
set bottleString to (createBottleString for numberOfBottles)
set lyrics to lyrics & bottleString & " of beer on the wall, " & bottleString & " of beer. " & return
set lyrics to lyrics & "Take one down and pass it around, " & return
set lyrics to lyrics & (createBottleString for (numberOfBottles - 1)) & " of beer on the wall. " & return
end repeat
set lyrics to lyrics & "No more bottles of beer on the wall, no more bottles of beer." & return
set lyrics to lyrics & "Go to the store and buy some more." & return
set lyrics to lyrics & "99 bottles of beer on the wall."
return lyrics
function beer(n);
if nargin<1, n=99; end
for i=n:-1:1,
disp([int2str(i) ' Bottles of beer on the wall,'])
disp([int2str(i) ' Bottles of beer,'])
disp('Take one down and pass it around,')
if i>1, disp([int2str(i-1) ' Bottles of beer on the wall.']),end
end
disp('No more bottles of beer on the wall!')
% ---------------------------------------------------------------
% Erlang version of the beer song
% Kent Engström, kenen@ida.liu.se
% ---------------------------------------------------------------
% See http://www.ericsson.se/cslab/erlang/ for Erlang information
% ---------------------------------------------------------------
-module(beer).
-export([song/0]).
song() ->
song(100).
song(0) ->
done;
song(N) ->
Bottles=bottles(N),
Bottles1=bottles(N-1),
io:format("~s of beer on the wall, ~s of beer.~n",
[Bottles,Bottles]),
io:format("Take one down and pass it around, ~s of beer on the wall.~n",
[Bottles1]),
song(N-1).
bottles(0)->
"no more bottles";
bottles(1)->
"1 bottle";
bottles(N)->
lists:append(integer_to_list(N)," bottles").
define beer(n);
define :inline PLURAL(N);
(N==1 and nullstring or "s")
enddefine;
lvars i;
for i from n by -1 to 1 do;
nl(1);
nprintf(PLURAL(i), i, '%P bottle%P of beer on the wall.');
nprintf(PLURAL(i), i, '%P bottle%P of beer!');
nprintf(i==1 and "it" or "one", 'Take %P down, pass it around.');
if i>1 then
nprintf(PLURAL(i-1), i-1, '%P more bottle%S of beer on the wall.');
else
npr('No more bottles of beer on the wall.');
endif;
endfor;
enddefine;
beer(100);
Sub MAIN
REM "99 bottles of beer on the wall"
REM Microsoft Word WordBasic macro language version
REM written by Mark Pilgrim, f8dy@netaxs.com
FileNew
beer$ = "99"
bottle$ = " bottles "
For count = 99 To 1 Step - 1
Insert beer$ + bottle$ + "of beer on the wall,"
InsertPara
Insert beer$ + bottle$ + "of beer,"
InsertPara
Insert "Take "
If count > 1 Then
Insert "one"
Else
Insert "it"
End If
Insert " down, pass it around,"
InsertPara
If count > 1 Then
beer$ = Str$(count - 1)
beer$ = Right$(beer$, Len(beer$) - 1)
If count = 2 Then bottle$ = " bottle "
Insert beer$ + bottle$ + "of beer on the wall."
InsertPara
Else
Insert "No more bottles of beer on the wall."
End If
InsertPara
Next
End Sub
(* Mathematica version of 99 Bottles of Beer *)
(* Bill Dall *)
Do[If[i>1,
Print[i, " more bottles of beer on the wall. ",i,
" more bottles of beer."];
Print["Take one down, pass it around."],
(* else *)
Print["1 more bottle of beer on the wall. 1 more bottle of beer."];
Print["Take one down, pass it around."];
Print["No more bottles of beer on the wall."]
], (* If *)
{i,99,1,-1}]
SUB main()
REM "99 bottles of beer", Superbase SBL version
REM written by Mark Pilgrim, f8dy@netaxs.com
REM [ If my boss is reading this, I'd just like to reassure
REM him that I wrote this on my own time. -MP ]
DIM i%%,beer$,bottle$
OPEN WINDOW "99 bottles of beer"
bottle$ = " bottles "
beer$ = "99"
FOR i%% = 99 TO 1 STEP - 1
? beer$ + bottle$ + "of beer on the wall,"
? beer$ + bottle$ + "of beer,"
? "Take " + IF (i%% > 1,"one","it") + " down, pass it around,"
IF i%% > 1 THEN
beer$ = LTRIM$ ( TRIM$ ( STR$ (i%% - 1)))
IF i%% = 2 THEN bottle$ = " bottle "
? beer$ + bottle$ + "of beer on the wall."
?
ELSE
? "No more bottles of beer on the wall."
END IF
NEXT
END SUB