99 Bottles Of Beer, es una cancion tipica anglosajona, al estilo un elefante se balanceba. En
http://www.99-bottles-of-beer.net/
podes encontrar el programa en más de 1253 variantes. Aca les dejo algunas.
Lenguaje Abap
REPORT z_99_bottles_of_beer.
*&---------------------------------------------------------------------*
*& Author: Dominik Ritter *
*&---------------------------------------------------------------------*
DATA: nobottles TYPE i.
START-OF-SELECTION.
nobottles = 99.
WHILE nobottles GT 1.
WRITE:/(2) nobottles, ' bottles of beer on the wall, '.
WRITE:/(2) nobottles, ' bottles of beer.'.
WRITE:/ 'Take one down,
pass
it around, '.
nobottles = nobottles - 1.
WRITE:/(2) nobottles, ' bottles of beer on the wall.'.
SKIP.
ENDWHILE.
WRITE:/ '1 bottle of beer on the wall,'.
WRITE:/ '1 bottle of beer.'.
WRITE:/ 'Take one down,
pass
it around, '.
WRITE:/ 'no more bottles of beer on the wall.'.
Lenguaje ActionScript 3
package {
import flash.display.MovieClip;
public class Beer extends MovieClip {
/* Set default song parameters: 'beer' in 'bottles' on a 'wall' */
private var bottleCount:int = 5;
private var liquid:String = 'beer';
private var container:String = 'bottle';
private var surface:String = 'wall';
/* song is comprised of 4 verses, which we loop through for each bottle */
private var verse:int = 0;
private var itVsOne:String = 'one';
private var plural:String = 's';
private var outNumber:String = bottleCount.toString();
/* song line for output */
private var songLine:String;
public function Beer() {
/* Loop through 4 times the numeber of bottles, 4 verses for each bottle */
var loopCount:int = bottleCount*4;
for (var i:int=0; i<loopCount; i++) {
sing();
}
}
/* set plural states*/
private function checkPlural(count:int):void {
if (count == 1) {
plural = '';
outNumber = 'one'
itVsOne = 'it';
} else {
outNumber = count.toString();
}
}
private function sing():String {
switch (verse) {
case 0 :
songLine = outNumber+' '+container+plural+' of '+liquid+' on the '+surface;
verse++;
break;
case 1 :
songLine = outNumber+' '+container+plural+' of '+liquid;
verse++;
break;
case 2 :
songLine = 'take '+itVsOne+' down,
pass
it around';
verse++;
break;
case 3 :
bottleCount--;
checkPlural(bottleCount);
verse = 0;
if (bottleCount == 0) {
songLine = 'no more '+container+'s of '+liquid+' on the '+surface;
} else {
songLine = outNumber+' '+container+plural+' of '+liquid+' on the '+surface;
}
break;
default :
}
return songLine;
}
}
}
Lenguaje Ada
-- Ada version of 99 Bottles of Beer
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Bottles is
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;
Lenguaje ASP
Microsoft's Active Server Pages language (called VBScript), meant to be embedded in HTML documents.
<HTML>
<HEAD>
<TITLE>99 Bottles of Beer</TITLE>
</HEAD>
<BODY>
<!-- Microsoft ASP (Active Server Pages) listing by Vince Curley
(
[email protected]
) -->
<%
n = 99
do
str = n & " bottle"
if n <> 1 then str = str & "s"
str = str & " of beer"
Response.Write str & " on the wall...<BR>"
Response.Write str & "!<BR>"
Response.Write "Take one down,
pass
it around...<BR>"
n = n - 1
if n > 0 then
str = n
else
str = "No "
end if
str = str & " bottle"
if n <> 1 then str = str & "s"
str = str & " of beer on the wall!<BR>"
Response.Write str
Response.Write "<BR>"
loop while n > 0
Response.Write "<FONT SIZE=7><STRONG>Buy more
beer!</STRONG></FONT>"
%>
</BODY>
</HTML>
Lenguaje Assambler
/***********************************************************************
* 99 Bottles of Beer in SPARC assembly language for Sun Solaris
* Compile with: as -o bottles.o bottles.s; ld -o bottles bottles.o
* Author: Ralf Horstmann <
[email protected]
>
***********************************************************************/
.section ".rodata"
.align 4
.botl0: .asciz "no more bottles"
.botl1: .asciz " bottle"
.botl2: .asciz " bottles"
.strg1: .asciz " of beer on the wall, "
.strg2: .asciz " of beer.\n"
.strg3: .asciz "Take one down and
pass
it around, "
.strg4: .asciz " of beer on the wall.\n\n"
.strg5: .ascii "Go to the store and buy some more,"
.asciz " 99 bottles of beer on the wall.\n"
SYSCALL_EXIT=1
SYSCALL_WRITE=4
STDOUT=1
.section ".text"
.globl main
/***********************************************************************/
main: save %sp, -96, %sp
mov 99, %l0 ! put the bottles onto the wall
loop: call putbtl
mov %l0, %o0 ! delay slot
sethi %hi(.strg1), %o0
call puts
or %o0, %lo(.strg1), %o0
call putbtl
mov %l0, %o0
sethi %hi(.strg2), %o0
call puts
or %o0, %lo(.strg2), %o0
cmp %l0, 0
be oob ! out of beer
dec %l0 ! n - 1
sethi %hi(.strg3), %o0
call puts
or %o0, %lo(.strg3), %o0
call putbtl
mov %l0, %o0
sethi %hi(.strg4), %o0
call puts
or %o0, %lo(.strg4), %o0
ba loop
nop
oob: sethi %hi(.strg5), %o0 ! no beer anymore
call puts
or %o0, %lo(.strg5), %o0
call exit
mov 0, %o0 ! exit code
/***********************************************************************
* print "n bottle(s)"/"no bottles" string, number in o0
*/
putbtl: save %sp, -96, %sp
cmp %i0, 1
ble 1f
nop
call putn ! > 1 bottle
mov %i0, %o0
sethi %hi(.botl2), %o0
call puts
or %o0, %lo(.botl2), %o0
ret
restore
1: cmp %i0, 0
be 1f
nop
call putn ! = 1 bottle
mov %i0, %o0
sethi %hi(.botl1), %o0
call puts
or %o0, %lo(.botl1), %o0
ret
restore
1: sethi %hi(.botl0), %o0 ! no bottles
call puts
or %o0, %lo(.botl0), %o0
ret
restore
/***********************************************************************
* print number in o0 to stdout
*/
putn: save %sp, -(96 + 8), %sp ! we need some stack space here
udiv %i0, 10, %o0 ! o0 = i0 / 10
umul %o0, 10, %o2 ! o2 = o0 * 10
sub %i0, %o2, %o2 ! o2 = i0 - o2 => remainder
cmp %o0, 0 ! if quotient is not 0, we call
bz 1f ! putn recursively with
nop ! quotient as parameter.
call putn
nop
1: add %o2, 0x30, %o2 ! convert remainder to ascii
stb %o2, [%sp + 96] ! store remainder to stack
add %sp, 96, %o1 ! put stack address into o1
mov STDOUT, %o0
call write ! print remainder to stdout
mov 1, %o2 ! one character only
ret
restore
/***********************************************************************
* print zero terminated string, o0: string pointer
*/
puts: save %sp, -96, %sp
mov %i0, %o0
1: ldub [%o0], %o1 ! load next byte from buffer
cmp 0, %o1
bne,a 1b ! ,a: inc instruction is only
inc %o0 ! executed if branch is taken
sub %o0, %i0, %o2 ! strlen is in o2 now
mov %i0, %o1
call write
mov STDOUT, %o0
nop
ret
restore
/***********************************************************************
* write syscall, o0: fd, o1: string pointer, o2: length
*/
write: mov SYSCALL_WRITE, %g1 ! syscall number passed in g1
ta 8
retl
nop
/***********************************************************************
* exit syscall, exit code in o0
*/
exit: mov SYSCALL_EXIT, %g1
ta 8
Lenguaje BASH
#!/bin/bash
#
# Bourne Again shell version of 99 Bottles - No loop - No recursion
# By Frédéric Lang (http://fr.lang.free.fr)
# Memorize count initial
max=${max:-99}
# Store count actual
typeset -i count=${next:-$max}
# Calculate next count
typeset -i next=count-1
# Evaluate count
if test $count -gt 0
then
middle="take one down,
pass
it around"
case $count in
1)
first="one bottle"
last="no more bottles"
;;
2)
first="2 bottles"
last="one bottle"
;;
*)
first="$count bottles"
last="$next bottles"
esac
order="source $0"
else
# Last occur
first="no more bottles"
middle="go to the shop and buy some more"
last="$max bottles"
order="exit 0"
fi
# Print sing
echo "$first of beer on the wall,"
echo "$first of beer,"
echo "$middle,"
echo "$last of beer on the wall."
echo
# Next occur
$order
Lenguaje C
/* The 99 Bottles of Beer Linux Kernel Module v1.1
* (supports multiple driver instances)
*
* by Stefan Scheler <sts[at]synflood[dot]de>
* August 2nd, 2005 - Ernstthal, Germany
*
* Usage:
* 1) compile the module
* 2) create the device: mknod /dev/bottles c 240 0
* 3) load the module: insmod bottles.ko
* 4) print the song with: cat /dev/bottles
*/
#include <linux/fs.h>
#include <linux/version.h>
#include <linux/module.h>
#include <linux/init.h>
#include <asm/uaccess.h>
#define DRIVER_MAJOR 240
#define BUFFERSIZE 160
#define PLURALS(b) (b>1)?"s":""
MODULE_AUTHOR("Stefan Scheler <sts[at]synflood[dot]de>");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("The 99 Bottles of Beer Linux Kernel Module");
MODULE_SUPPORTED_DEVICE("Bottle of Beer");
struct _instance_data {
int bytes_avail, bytes_sent, bottles;
char buf[BUFFERSIZE];
};
static void fill_buffer(char *buf, int b) {
char line[BUFFERSIZE/2];
if (b>0) {
sprintf(buf, "%d bottle%s of beer on the wall, %d bottle%s of beer.\n" \
"Take one down and
pass
it around, ", b, PLURALS(b), b, PLURALS(b));
if (b==1)
strcat(buf, "no more bottles of beer on the wall.\n");
else {
sprintf(line, "%d bottle%s of beer on the wall.\n", b-1, PLURALS(b-1));
strcat(buf, line);
}
} else {
sprintf(buf, "No more bottles of beer on the wall, no more bottles of beer.\n" \
"Go to the store and buy some more, 99 bottles of beer on the wall.\n");
}
}
static ssize_t driver_read(struct file *instance, char *userbuffer, size_t count, loff_t *offset)
{
struct _instance_data *iptr = (struct _instance_data *)instance->private_data;
int to_copy;
int not_copied;
refillbuffer:
fill_buffer(iptr->buf, iptr->bottles);
iptr->bytes_avail = strlen(iptr->buf)+1;
to_copy = iptr->bytes_avail-iptr->bytes_sent;
if (to_copy>0) {
if (to_copy> count) to_copy=count;
not_copied=copy_to_user(userbuffer, iptr->buf+iptr->bytes_sent, to_copy);
iptr->bytes_sent += to_copy-not_copied;
return (to_copy-not_copied);
}
if ((to_copy==0) && (iptr->bottles>0)) {
iptr->bytes_sent=0;
iptr->bottles--;
goto refillbuffer;
}
return 0;
}
int driver_open(struct inode *devicefile, struct file *instance) {
struct _instance_data *iptr;
iptr = (struct _instance_data *)kmalloc(sizeof(struct _instance_data), GFP_KERNEL);
if (!iptr)
return -1;
iptr->bytes_sent = 0;
iptr->bottles = 99;
instance->private_data = iptr;
return 0;
}
int driver_close(struct inode *devicefile, struct file *instance) {
if (instance->private_data)
kfree(instance->private_data);
return 0;
}
static struct file_operations fops = {
.owner = THIS_MODULE,
.open = driver_open,
.release = driver_close,
.read = driver_read,
};
static int __init __init_module(void) {
if(register_chrdev(DRIVER_MAJOR, "99 Bottles of Beer", &fops) == 0)
return 0;
return -EIO;
}
static void __exit __cleanup_module(void) {
unregister_chrdev(DRIVER_MAJOR, "99 Bottles of Beer");
}
module_init(__init_module);
module_exit(__cleanup_module);
Lenguaje C#
/// Implementation of Ninety-Nine Bottles of Beer Song in C#.
/// What's neat is that .NET makes the Binge class a
/// full-fledged component that may be called from any other
/// .NET component.
///
/// Paul M. Parks
/// http://www.parkscomputing.com/
/// February 8, 2002
///
using System;
namespace NinetyNineBottles
{
/// <summary>
/// References the method of output.
/// </summary>
public delegate void Writer(string format, params object[] arg);
/// <summary>
/// References the corrective action to take when we run out.
/// </summary>
public delegate int MakeRun();
/// <summary>
/// The act of consuming all those beverages.
/// </summary>
public class Binge
{
/// <summary>
/// What we'll be drinking.
/// </summary>
private string beverage;
/// <summary>
/// The starting count.
/// </summary>
private int count = 0;
/// <summary>
/// The manner in which the lyrics are output.
/// </summary>
private Writer Sing;
/// <summary>
/// What to do when it's all gone.
/// </summary>
private MakeRun RiskDUI;
public event MakeRun OutOfBottles;
/// <summary>
/// Initializes the binge.
/// </summary>
/// <param name="count">How many we're consuming.</param>
/// <param name="disasterWaitingToHappen">
/// Our instructions, should we succeed.
/// </param>
/// <param name="writer">How our drinking song will be heard.</param>
/// <param name="beverage">What to drink during this binge.</param>
public Binge(string beverage, int count, Writer writer)
{
this.beverage = beverage;
this.count = count;
this.Sing = writer;
}
/// <summary>
/// Let's get started.
/// </summary>
public void Start()
{
while (count > 0)
{
Sing(
@"
{0} bottle{1} of {2} on the wall,
{0} bottle{1} of {2}.
Take one down,
pass
it around,",
count, (count == 1) ? "" : "s", beverage);
count--;
if (count > 0)
{
Sing("{0} bottle{1} of {2} on the wall.",
count, (count == 1) ? "" : "s", beverage);
}
else
{
Sing("No more bottles of {0} on the wall.", beverage, null);
}
}
Sing(
@"
No more bottles of {0} on the wall,
No more bottles of {0}.", beverage, null);
if (this.OutOfBottles != null)
{
count = this.OutOfBottles();
Sing("{0} bottles of {1} on the wall.", count, beverage);
}
else
{
Sing("First we weep, then we sleep.");
Sing("No more bottles of {0} on the wall.", beverage, null);
}
}
}
/// <summary>
/// The song remains the same.
/// </summary>
class SingTheSong
{
/// <summary>
/// Any other number would be strange.
/// </summary>
const int bottleCount = 99;
/// <summary>
/// The entry point. Sets the parameters of the Binge and starts it.
/// </summary>
/// <param name="args">unused</param>
static void Main(string[] args)
{
Binge binge =
new Binge("beer", bottleCount, new Writer(Console.WriteLine));
binge.OutOfBottles += new MakeRun(SevenEleven);
binge.Start();
}
/// <summary>
/// There's bound to be one nearby.
/// </summary>
/// <returns>Whatever would fit in the trunk.</returns>
static int SevenEleven()
{
Console.WriteLine("Go to the store, get some more...");
return bottleCount;
}
}
}
Lenguaje C++
// C++ version of 99 Bottles of beer
// programmer: Tim Robinson
[email protected]
// Corrections by Johannes Tevessen
#include <iostream>
using namespace std;
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;
}
Lenguaje COBOL
IDENTIFICATION DIVISION.
PROGRAM-ID. 99-Bottles-of-Beer-On-The-Wall.
AUTHOR. Joseph James Frantz.
*COMMENTS.
******************************************************************
* PURPOSE:
* This is a sample COBOL program to display the lyrics of the
* song "99 Bottles of Beer on the Wall."
* This version of the COBOL 99 beers program demonstrates a few
* features of COBOL:
*
* 1. PERFORM VARYING, Cobol's version of a Loop.
* 2. ADD/SUBTRACT with GIVING for math calculations.
* 3. EVALUATE/WHEN, Cobol's version of Case.
* 4. INSPECT/TALLYING, which finds the number of specified
* characters in a variable.
* 5. Reference Modification:
* Var-name(Start character:Number of characters)
* which is essentially Cobol's version of text subscripting.
* 6. Long descriptive variable names.
* 7. Use of SPACES and ZEROES for field/display values.
* 8. Highlight the self documenting nature of COBOL.
******************************************************************
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Keeping-Track-Variables.
05 Bottles PIC S99 VALUE 0.
05 Remaining-Bottles PIC S99 VALUE 0.
05 Counting PIC 99 VALUE 0.
05 Start-Position PIC 99 VALUE 0.
05 Positions PIC 99 VALUE 0.
PROCEDURE DIVISION.
PASS
-AROUND-THOSE-BEERS.
PERFORM VARYING Bottles FROM 99 BY -1 UNTIL Bottles = -1
DISPLAY SPACES
SUBTRACT 1 FROM Bottles GIVING Remaining-Bottles
EVALUATE Bottles
WHEN 0
DISPLAY "No more bottles of beer on the wall, "
"no more bottles of beer."
DISPLAY "Go to the store and buy some more, "
"99 bottles of beer on the wall."
WHEN 1
DISPLAY "1 bottle of beer on the wall, "
"1 bottle of beer."
DISPLAY "Take one down and
pass
it around, "
"no more bottles of beer on the wall."
WHEN 2 Thru 99
MOVE ZEROES TO Counting
INSPECT Bottles,
TALLYING Counting FOR LEADING ZEROES
ADD 1 TO Counting GIVING Start-Position
SUBTRACT Counting FROM 2 GIVING Positions
DISPLAY Bottles(Start-Position:Positions)
" bottles of beer on the wall, "
Bottles(Start-Position:Positions)
" bottles of beer."
MOVE ZEROES TO Counting
INSPECT Remaining-Bottles TALLYING
Counting FOR LEADING ZEROES
ADD 1 TO Counting GIVING Start-Position
SUBTRACT Counting FROM 2 GIVING Positions
DISPLAY "Take one down and
pass
it around, "
Remaining-Bottles(Start-Position:Positions)
" bottles of beer on the wall."
END-EVALUATE
END-PERFORM
STOP RUN.
Lenguaje D
import std.stdio;
import std.string;
void main() {
int bottles = 99;
char[] text = "99 bottles";
while (bottles != 0) {
writefln(text, " of beer on the wall,");
writefln(text, " of beer.");
writefln("Take one down,
pass
it around,");
if (--bottles == 1) {
text = "1 bottle";
} else {
text = format("%d bottles", bottles);
}
writefln(text, " of beer on the wall.\n");
}
}
Lenguaje DHTML
DTML (Document Template Markus Language) is the scripting language
of the web management tool 'Zope'.
<dtml-call "REQUEST.set('i',_.range(0,100,1))">
<dtml-call "REQUEST.set('r',99)">
<dtml-in i reverse>
<dtml-if expr="r==1">
<dtml-var sequence-item> bottle of beer on the wall, <dtml-var
sequence-item> bottle of beer
take one down,
pass
it around,
<dtml-var sequence-item> bottle of beer.
<dtml-elif expr="r==0">
no more bottles of beer on the wall.
Go to the store, buy some more.
<dtml-else>
<dtml-var sequence-item> bottles of beer on the wall, <dtml-var
sequence-item> bottles of beer
take one down,
pass
it around,
<dtml-var sequence-item> bottles of beer.
</dtml-if>
<dtml-call "REQUEST.set('r',r-1)">
</dtml-in>
Lenguaje Eiffel
class SHELF
-- A shelf of bottles
creation
make
feature
make (l_bottles: INTEGER) is
require
positive_bottles: l_bottles >= 0
do
bottles := l_bottles
end
remove is
require
bottles_exist: bottles > 0
do
bottles := bottles - 1
ensure
removed: bottles = old bottles - 1
end
bottles: INTEGER
short_description: STRING is
do
if bottles = 0 then
Result := "No"
else
Result := bottles.out
end
Result.append (" bottle")
if bottles /= 1 then
Result.append ("s")
end
Result.append (" of beer")
ensure
result_exists: Result /= Void
end
description: STRING is
do
Result := short_description
Result.append (" on the wall, ")
Result.append (short_description)
Result.append ("%N")
ensure
result_exists: Result /= Void
end
empty: BOOLEAN is
do
Result := bottles = 0
end
invariant
positive_bottles: bottles >= 0
end -- class SHELF
class BEER
-- Produuce the ditty
-- Nick Leaton
creation
make
feature
shelf: SHELF
make is
do
from
!!shelf.make (99)
until
shelf.empty
loop
io.put_string (shelf.description)
shelf.remove
io.put_string ("Take one down,
pass
it all around%N%N")
end
io.put_string (shelf.description)
io.put_string ("Go to the store and buy some more%N%N")
shelf.make (99)
io.put_string (shelf.description)
end
end -- class BEER
Programming language: Eiffel
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.put_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.put_new_line;
end -- loop
io.put_string("Go to the store and buy some more,");
io.put_new_line;
io.put_string("99 bottles of beer on the wall.");
io.put_new_line;
end;
end -- class BEERS
Lenguaje Fortran
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
Lenguaje GeneXus
/* *******************************************
99 beers
Written by Enrique Almeida
GeneXus 8.0 - Generated in C# - Console Application.
****************************************** */
&Bottles=99
do while &Bottles > 0
do 'Bottles'
Msg(&BottlesTXT+ "of beer on the Wall, " + &BottlesTXT+ "of beer," , status)
&Bottles=&Bottles-1
do 'Bottles'
Msg("take one down,
pass
it around, " + &BottlesTXT+ "of beer on the wall." , status)
Msg(NewLine(),status)
enddo
Msg("No more bottles of beer on the wall. No more bottles of beer...", status)
Msg("Go to the store and buy some more...99 bottles of beer." , status)
return
//**************************************
// Check if use bottle or bottles
sub 'Bottles'
If &Bottles > 1
&BottlesTXT=str(&Bottles,2) + " bottles "
else
If &Bottles = 1
&BottlesTXT=str(&Bottles,2) + " bottle "
else
&BottlesTXT="No more bottles "
endif
endif
endsub
Lenguaje Haskell
--Version of http://99-bottles-of-beer.net/language-haskell-1070.html
--using guards.
bottles :: Int -> String
bottles n
|n == 0 = "no more bottles"
|n == 1 = "1 bottle"
|n > 1 = show n ++ " bottles"
verse :: Int -> String
verse n
|n == 0 = "No more bottles of beer on the wall, no more bottles of beer.\n"
++ "Go to the store and buy some more, 99 bottles of beer on the wall."
|n>0 = bottles n ++ " of beer on the wall, " ++ bottles n ++ " of beer.\n"
++ "Take one down and
pass
it around, " ++ bottles (n-1)
++ " of beer on the wall.\n"
main = mapM (putStrLn . verse) [99,98..0]
Lenguaje Hope
<a href=http://www-ala.doc.ic.ac.uk/~rap/Hope/>Click</a> for more information.
! Hope Version of 99 Bottles of Beer : RAM-Biter!!!
! Tested on a SPARC classic, SunSolaris 2
! Programmer: Wolfgang Lohmann
[email protected]
dec app :( list ( char ) X list ( char )) -> list ( char ) ;
dec i2c : num -> char;
dec i2s : num -> list(char);
dec beer : num -> list(char);
--- app ( nil , w )
<= w ;
--- app (( a :: v ), w )
<=( a :: app ( v , w )) ;
--- i2c(0) <= '0';
--- i2c(1) <= '1';
--- i2c(2) <= '2';
--- i2c(3) <= '3';
--- i2c(4) <= '4';
--- i2c(5) <= '5';
--- i2c(6) <= '6';
--- i2c(7) <= '7';
--- i2c(8) <= '8';
--- i2c(9) <= '9';
--- i2s(x) <= if x < 10 then [i2c(x)] else
app(i2s(x div 10), i2s( x mod 10));
--- beer(x) <= if x = 1 then app( i2s(x),
" bottle of beer. No more beer on the wall.")
else app( app( app( app( app(
i2s(x),
" bottles of beer on the wall, "),
i2s(x)),
" bottles of beer. "),
"Take one down,
pass
it around. "),
beer(y))
where y== x-1;
Lenguaje Informix 4gl
MAIN
DEFINE i_bottle SMALLINT,
i_bottle_str CHAR(20),
i_bottle_temp SMALLINT,
s_bottle CHAR(15),
i_start SMALLINT
LET i_start = 99
FOR i_bottle = i_start TO 1 STEP -1
LET i_bottle_temp = i_bottle -1
IF i_bottle = 1 THEN
LET s_bottle = "bottle"
ELSE
LET s_bottle = "bottles"
END IF
LET i_bottle_str = i_bottle USING "<<"
IF i_bottle = 0 THEN
LET i_bottle_str = "No more bottles"
END IF
DISPLAY i_bottle USING "<<", " ", s_bottle CLIPPED, " of beer on the wall, ", i_bottle USING
"<<", " ", s_bottle CLIPPED, " of beer."
CASE i_bottle_temp
WHEN 1
LET s_bottle = "bottle"
WHEN 0
LET s_bottle = "no more bottles"
OTHERWISE
LET s_bottle = "bottles"
END CASE
DISPLAY "Take one down and
pass
it around, ", i_bottle_temp USING "<<", " ", s_bottle CLIPPED, "
of beer on the wall."
DISPLAY " "
END FOR
DISPLAY "No more bottles of beer on the wall, no more bottles of beer."
DISPLAY "Go to the store and buy some more, ", i_start USING "<<", " bottles of beer on the wall."
END MAIN
Lenguaje Java
/* the main method instantiates drinkers and directs them to
a newly-instantiated wall of beer.
*/
public class Sing99Bob {
public static void main(String[] args) {
((NeedToFindBeer)(new Drinkers())).pointAtBeer(new WallOfBeer());
}
}
interface NeedToFindBeer { void pointAtBeer(WallOfBeer wob); }
/* an instance of Drinkers, after being pointed at a wall containing
beer, will periodically take one down. The singing is driven by
the taking of the beer.
*/
class Drinkers extends Thread implements NeedToFindBeer {
static final int drinkRate = 2;
WallOfBeer ourBeer;
public void run() {
while (ourBeer.takeOne()>0) {
try { Thread.sleep(drinkRate*1000); } catch (InterruptedException ignore) {}
}
}
public void pointAtBeer(WallOfBeer wob) {
ourBeer = wob;
this.start();
}
}
interface Countable { int howMany(); }
/* an instance of a WallOfBeer will maintain a count of the
beer bottles. The wall has an associated Narrator who
reports each time the number of bottles is changed.
*/
class WallOfBeer implements Countable {
static final int full = 99;
int count = 0;
WallWatcher ww;
{
ww = new Narrator();
putSome(full);
}
void putSome(int some) {
count += some;
if (ww!=null) ww.wallEvent(this);
}
int takeOne() {
count--;
if (ww!=null) ww.wallEvent(this);
return count;
}
public int howMany() { return count; }
}
interface WallWatcher { void wallEvent(Countable wob); }
/* an instance of Narrator sings the verse each time it is
notified that something has happened to the wall. This
narrator attempts to be grammatical, and uses words for
the bottle count (singers sing words not numerals). The
singing is paced, not merely lump-dumped to sysout.
*/
class Narrator implements WallWatcher {
static final int singspeed = 500;
public void wallEvent(Countable wob) {
int b = wob.howMany();
try {
System.out.print(bob(b, true)+onwall+", ");
Thread.sleep(singspeed);
System.out.print(bob(b, false)+".\n");
Thread.sleep(singspeed);
System.out.print((b>0)?takedown:gostore);
Thread.sleep(singspeed);
System.out.print((b>0)?bob(b-1, false):bob(WallOfBeer.full, false));
System.out.print(onwall+".\n");
} catch (InterruptedException ignore) {}
}
static final String bob(int i, boolean c) {
String word = word(i);
if (c) word = (word.substring(0, 1).toUpperCase())+word.substring(1);
return word+" bottle"+((i==1)?"":"s")+" of beer";
}
static final String word(int i) {
if (i==0) return "no more";
if (i<20) return units;
return tens[i/10]+((units[i%10]=="")?"":"-"+units[i%10]);
}
static final String
onwall = " on the wall",
takedown = "Take one down and
pass
it around, ",
gostore = "Go to the store, get some more, ";
static final String[]
tens = {"", "", "twenty", "thirty", "forty",
"fifty", "sixty", "seventy", "eighty", "ninety"},
units = {"", "one", "two", "three", "four", "five", "six", "seven",
"eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen",
"fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
}
Lenguaje Java 2 Micro Edition
/*
* bottles.java - 99 Bottles of Beer
* J2ME Midlet for MIDP 1.0 compatible mobile devices, tested on nokia 6100
* by Stefan Scheler <sts[at]synflood[dot]de> on 16-June-2004
*
*/
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class bottles extends MIDlet {
private Display mDisplay;
private Form mForm;
private StringItem mString;
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public bottles() {
mString = new StringItem("", "");
mForm = new Form("99 Bottles of Beer");
mForm.append(mString);
mDisplay = Display.getDisplay(this);
mDisplay.setCurrent(mForm);
}
public void appendText(String s) {
mString.setText(mString.getText()+s);
}
public void startApp() {
for (int i = 99; i > 1; i--) {
int j = i-1;
appendText(i + " bottles of beer on the wall, " + i + " bottles " +
"of beer. Take one down,
pass
it around, " + j + " ");
if (j != 1) appendText("bottles"); else appendText("bottle");
appendText(" of beer on the wall.\n");
}
appendText("1 bottle of beer on the wall, 1 bottle of beer. Take one " +
"down,
pass
it around, no more bottles of beer on the wall.");
appendText("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 on the wall.");
}
}
JQuery
function displayVerse(num) {
switch(num) {
case 0 : verse = "No more bottles of beer on the wall, ";
verse += "no more bottles of beer.";
verse += "<br />Go to the store and buy some more, "
verse += "99 bottles of beer on the wall.";
break;
case 1 : verse = num + " bottle of beer on the wall, ";
verse += num + " bottle of beer.";
verse += "<br />Take one down and
pass
it around, "
verse += "no more bottles of beer on the wall.";
break;
case 2 : verse = num + " bottles of beer on the wall, ";
verse += num + " bottles of beer.";
verse += "<br />Take one down and
pass
it around, ";
verse += (num-1) + " bottle of beer on the wall.";
break;
default : verse = num + " bottles of beer on the wall, ";
verse += num + " bottles of beer.";
verse += "<br />Take one down and
pass
it around, ";
verse += (num-1) + " bottles of beer on the wall.";
break;
}
$("body").prepend("<p style=\"display:none;\">" + verse + "</p>");
$("p").css("color","#CCC").css("font-family","Arial,sans-serif").css("font-weight","normal");
$("p:nth-child(3)").css("color","#999");
$("p:nth-child(2)").css("color","#666");
$("p:nth-child(1)").css("color","#333");
$("p:first-child").css("color","#000").css("font-weight","bold").show("slow");
}
$(document).ready(function() {
for(i=99;i>=0;i--)
setTimeout("displayVerse(" + i + ")",(99-i)*1000);
});
Lenguaje LotusScript
Sub Click(Source As Button)
' -----------------------------------------------------
' 99 Bottle of Beer on the Wall, in LotusScript
' By Sean Heffernan
' -----------------------------------------------------
Dim ui As New NotesUIWorkspace
Dim s As String
Dim n As Integer
For n = 99 To 1 Step -1
If n > 1 Then
s = Cstr(n) + " bottles of beer on the wall. " +
Cstr(n) + " bottles of beer. Take one down,
pass
it around. " + Cstr(n-1)
+ " bottles of beer on the wall."
Else
s = "Only one more bottle of beer on the wall.
Only one more bottle of beer. Take it down,
pass
it around. No more
bottles of beer on the wall."
End If
Call ui.Prompt ( PROMPT_OK, "99 Bottles of Beer ...", s )
Next
End Sub
Lenguaje Matlab
% MATLAB *vectorized* version of "99 bottles of beer"
% Rich Stein (
[email protected]
)
bottles = [98:-1:3]; % bottles 98 to 3 (99, 2 & 1 are treated as special case)
lines = 3; % need the number of bottles at the beginning of 3 lines
num_array = ones(lines,1) * bottles; % bottles is a (1x96) array
format_plural1 = '%d bottles of beer on the wall,\n%d bottles of beer,\n';
format_plural2 = 'Take one down,
pass
it around,\n%d bottles of beer on the wall.\n\n';
format_sing1 = '%d bottle of beer on the wall,\n%d bottle of beer,\n';
format_sing2 = 'Take one down,
pass
it around,\n%d bottle of beer on the wall.\n\n';
format_none2 = 'Take it down,
pass
it around,\nNo bottles of beer on the wall.\n';
% bottles 99, 2 & 1 are treated as special cases
fprintf([format_plural1 format_plural2], 99,99,num_array,2)
fprintf([format_plural1 format_sing2], 2,2,1)
fprintf([format_sing1 format_none2], 1,1)
Lenguaje Maya Embedded Language
Mel, or "Maya Embedded Language" is an interpreted scripting language used
for the 3d animation software Maya.
// This version is perhaps cleaner to read
for( $i = 99; $i > 0; $i++){
print( $i+" bottles of beer on the wall,\n"
+$i+" bottles of beer.\nTake one down,
pass
it around,\n"
+($i-1)+ " bottles of beer on the wall!\n"));
}
Lenguaje Mercury
A purely declarative logic programming language.
<a href="http://www.cs.mu.oz.au/~zs/mercury.html">Click</a> for more information.
% file: beer.m
% author: Fergus Henderson <
[email protected]
>
% date: Thursday 9th November 1995
:- module beer.
:- interface.
:- import_module io.
:- pred main(io__state::di, io__state::uo) is det.
:- implementation.
:- import_module int.
main --> beer(99).
:- pred beer(int::in, io__state::di, io__state::uo) is det.
beer(N) -->
( { N = 0 } ->
io__write_string("Go to the store and buy some more!")
;
bottles(N),
io__write_string(" on the wall,\n"),
bottles(N),
io__write_string(".\n"),
io__write_string("Take one down,
pass
it around,\n"),
{ N1 is N - 1 },
bottles(N1),
io__write_string(" on the wall.\n\n"),
beer(N1)
).
:- pred bottles(int::in, io__state::di, io__state::uo) is det.
bottles(N) -->
( { N = 0 } ->
io__write_string("No more bottles of beer")
; { N = 1 } ->
io__write_string("1 bottle of beer")
;
io__write_int(N),
io__write_string(" bottles of beer")
).
99 Bottles Of Beer - En más de 50 Lenguajes! (Primera Parte
Datos archivados del Taringa! original
5puntos
2,805visitas
0comentarios
Actividad nueva en Posteamelo
0puntos
3visitas
0comentarios
Dar puntos: