99 bottles of beer: Difference between revisions

Tags: Mobile edit Mobile web edit
(40 intermediate revisions by 18 users not shown)
Line 215:
cl_demo_output=>display( ).
</syntaxhighlight>
 
=={{header|ABC}}==
<syntaxhighlight lang="abc">HOW TO RETURN bottles n:
SELECT:
n<0: RETURN "99 bottles"
n=0: RETURN "No more bottles"
n=1: RETURN "1 bottle"
n>1: RETURN "`n` bottles"
 
HOW TO SING VERSE n:
WRITE "`bottles n` of beer on the wall,"/
WRITE "`bottles n` of beer,"/
SELECT:
n=0: WRITE "Go to the store and buy some more,"/
n=1: WRITE "Take it down and pass it around,"/
n>1: WRITE "Take one down and pass it around,"/
WRITE "`bottles (n-1)` of beer on the wall."/
WRITE /
 
FOR n IN {0..99}:
SING VERSE 99-n</syntaxhighlight>
 
=={{header|ACL2}}==
See [[99 Bottles of Beer/Lisp]]
 
=={{header|Acornsoft Lisp}}==
See [[99 Bottles of Beer/Lisp]]
 
Line 956 ⟶ 980:
 
-- At the prompt, type 'N beer !' (no quotes), where N is the number of stanzas you desire</syntaxhighlight>
 
=={{header|BabyCobol}}==
<syntaxhighlight lang="cobol">
* Pointing out some interesting things:
* - BY 0 subclause of VARYING (illegal in some COBOL dialects)
* - PERFORM THROUGH with internal/external GO TOs
* - using non-reserved keywords (END, DATA)
* - ALTER (works the same way in COBOL)
* - fall-through from MANY-BOTTLES
* - the last NEXT SENTENCE does nothing (plays the role of EXIT)
IDENTIFICATION DIVISION.
PROGRAM-ID. 99 BOTTLES.
DATA DIVISION.
01 DATA PICTURE IS 999.
PROCEDURE DIVISION.
LOOP VARYING DATA FROM 99 BY 0
PERFORM COUNT-BOTTLES THROUGH END
DISPLAY DATA "bottles of beer"
DISPLAY "Take one down, pass it around"
SUBTRACT 1 FROM DATA
IF DATA = 1
THEN ALTER COUNT-BOTTLES TO PROCEED TO SINGLE-BOTTLE
END
PERFORM COUNT-BOTTLES THROUGH END
DISPLAY ""
END.
NO-BOTTLES-LEFT.
DISPLAY "No bottles of beer on the wall"
DISPLAY ""
DISPLAY "Go to the store and buy some more"
DISPLAY "99 bottles of beer on the wall".
STOP.
COUNT-BOTTLES.
GO TO MANY-BOTTLES.
SINGLE-BOTTLE.
DISPLAY DATA "bottle of beer on the wall".
GO TO NO-BOTTLES-LEFT.
MANY-BOTTLES.
DISPLAY DATA "bottles of beer on the wall".
END.
NEXT SENTENCE.
</syntaxhighlight>
 
=={{header|BASIC}}==
Line 1,442 ⟶ 1,508:
p "One bottle of beer on the wall, one bottle of beer!"
p "Take one down, pass it around, no more bottles of beer on the wall."</syntaxhighlight>
 
=={{header|Bruijn}}==
<syntaxhighlight lang="bruijn">
:import std/Combinator .
:import std/Number .
:import std/String .
 
main [y [[=?0 case-end case-rec]] (+99)]
case-rec n ++ t1 ++ n ++ t2 ++ t3 ++ n ++ t1 ++ "\n" ++ (1 --0)
n number→string 0
t1 " bottles of beer on the wall\n"
t2 " bottles of beer\n"
t3 "Take one down, pass it around\n"
case-end empty
</syntaxhighlight>
 
=={{header|BQN}}==
Line 1,943 ⟶ 2,024:
WriteLine("Go to the store to buy some more, 99 bottles of beer on the wall...");
}</syntaxhighlight>
 
=={{header|C/vFP16}}==
<syntaxhighlight
lang="cpp">#pragma SCH_64_16_IFP
#import <jobsched.c>
 
__attr(@canschedule)
volatile constricts async UVOID <__INVAR const T>base_000000 __PCON(
impure VFCTX_t^ ct_base,
impure MCHR_t^ sched_arg,
__LVAR <const T>XVF_fntype_t^ f,
<out VF_QSWitch_t>XVF_fn_t^ switchctx
) __ARGFILL {
VF_Xsched_ILock(ct_base, $->sched);
 
captured __VFObj <>VF_KeDbg^ ki = VF_Xg_KeDbg_Instance();
 
captured deferred <__VF_T_Auto>__VF_Auto^ vfke = copyof VF_KeDbg_GetRstream<MCHR_t^>(captures ki);
VF_Gsched_SOBFree(sched_arg);
VF_Gsched_Alloc_U16(65535);
VF_Msched_MChr_lim(1496);
VF_Osched_Begin();
VF_Fsched_Add2(%beer_000099);
 
VF_Xsched_IUnlock(ct_base, $->sched);
$switchctx(IMPURE_CTX, %beer_000099(%vfke));
}
 
__attr(@eUsesIo)
impure constricts UVOID synchronized beer_000099(
impure __noinline <MCHR_t^>RIGHTSTREAM_t^ outrs
) __NFILL {
pure UVOID^ uvid = __attr(@purify) $UVOID.;
while ( 99 > ((volatile NUM_t)^(NUM_t^)(uvid))++ ) {
VF_STM_Out_NUM((NUM_t^)uvid);
VF_STM_Out_x(__Dynamic C"bottles on the wall.\nPut one down, pass it around\n");
}
return $__;
}
</syntaxhighlight>
 
=={{header|C++}}==
Line 3,705 ⟶ 3,829:
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
func$ checkPluralbottle num . word$ .
if num = 1
word$ =return "bottle"
else
word$ = "bottles"
.
return "bottles"
.
#
for i = 99 step -1 to 1
repeat
call checkPlural i pluralWord$
print i & " " & pluralWord$bottle i & " of beer on the wall"
print i & " " & pluralWord$bottle i & " of beer"
print "Take one down, pass it around"
call checkPlural i -= 1 pluralWord$
ifuntil i - 1 = 0
print i & print" "No more& bottlesbottle i & " of beer on the wall"
else
print i - 1 & " " & pluralWord$ & " of beer on the wall"
.
print ""
.
print "No more bottles of beer on the wall"
</syntaxhighlight>
 
Line 3,755 ⟶ 3,876:
 
=={{header|Ecstasy}}==
<syntaxhighlight lang="java">module Bottles {
void run() {
@Inject Console console;
void run()
{
function String(Int) num = i -> i==0 ? "No" : i.toString();
function String(Int) bottles = i -> i==1 ? "bottle" : "bottles";
 
for@Inject (IntConsole remain : 99..1)console;
for (Int remain : 99..1) {
console.print($|{num(remain)} {bottles(remain)} of beer on the wall
|{num(remain)} {bottles(remain)} of beer
Line 3,771 ⟶ 3,889:
|
);
}
}
}</syntaxhighlight>
}</syntaxhighlight>
 
=={{header|Egel}}==
Line 3,964 ⟶ 4,082:
 
=={{header|Elena}}==
ELENA 56.0 :
<syntaxhighlight lang="elena">import system'routines;
import extensions;
Line 3,975 ⟶ 4,093:
= self.toPrintable() + (self != 1).iif(" bottles"," bottle");
bottleEnumerator() = new Variable(self).doWith::(n)
{
^ new Enumerator
Line 3,981 ⟶ 4,099:
bool next() = n > 0;
get Value() = new StringWriter()
.printLine(n.bottleDescription()," of beer on the wall")
.printLine(n.bottleDescription()," of beer")
.printLine("Take one down, pass it around")
.printLine((n.reduce:(1)).bottleDescription()," of beer on the wall");
reset() {}
enumerable() = __targetweak self;
}
};
Line 3,998 ⟶ 4,116:
var bottles := 99;
bottles.bottleEnumerator().forEach:(printingLn)
}</syntaxhighlight>
{{out}}
Line 4,085 ⟶ 4,203:
 
=={{header|EMal}}==
This version writes the lyrics as described here: https://99-bottles-of-beer.net/lyrics.html
<syntaxhighlight lang="emal">
type NinetynineBottles
int DEFAULT_BOTTLES_COUNT = 99
text BASE_SUBJECT = "bottle"
model
int initialBottlesCount, bottlesCount
new by int =bottlesCount
me.initialBottlesCount = bottlesCount
me.bottlesCount = bottlesCount
end
fun subject = text by block do return <|when(me.bottlesCount == 1, BASE_SUBJECT"bottle", BASE_SUBJECT + "sbottles") end
fun bottles = text by block do return <|when(me.bottlesCount == 0, "Nono more", text!me.bottlesCount) end
fun goToWall = void by block
text line = me.bottles() + " " + me.subject() + " of beer on the wall, " +
me.bottles() + " " + me.subject() + " of beer."
if me.bottlesCount == 0 do line[0] = line[0].upper() end # text can be modified
writeLine(line)
end
Line 4,132 ⟶ 4,250:
 
1 bottle of beer on the wall, 1 bottle of beer.
Take one down and pass it around, Nono more bottles of beer on the wall.
 
No more bottles of beer on the wall, Nono more bottles of beer.
Go to the store and buy some more, 2 bottles of beer on the wall.
</pre>
Line 6,166 ⟶ 6,284:
2 bottles of beer on the wall, 2 bottles of beer; take one down and pass it around, 1 bottle of beer on the wall
1 bottle of beer on the wall, 1 bottle of beer; take one down and pass it around, 0 bottles of beer on the wall </pre>
 
=={{header|Jakt}}==
<syntaxhighlight lang="jakt">
fn bottle_string(bottle_count: i64) throws -> String => match bottle_count {
0 => "No more bottles"
1 => "1 bottle"
else => format("{} bottles", bottle_count)
}
 
fn main() {
mut bottle_count = 99
while bottle_count > 0 {
println("{} of beer on the wall", bottle_string(bottle_count))
println("{} of beer", bottle_string(bottle_count))
println("Take one down, pass it around")
bottle_count--
println("{} of beer on the wall", bottle_string(bottle_count))
 
if bottle_count > 0 {
println("")
}
}
}
</syntaxhighlight>
 
=={{header|Janet}}==
Line 8,952 ⟶ 9,094:
70 PRINT BOTTLES-1 BOTTLES$ WALL$
80 NEXT</syntaxhighlight>
 
=={{header|Nutt}}==
<syntaxhighlight lang="Nutt">
module main imports native.io.output.say
 
for i|->{1,2..99;<|>) do
say(""+i+" bottles of beer on the wall, "+i+" bottles of beer")
say("Take one down and pass it around, "+(i-1)+" bottles of beer on the wall.")
done
 
end
</syntaxhighlight>
 
=={{header|OASYS}}==
Line 11,441 ⟶ 11,595:
bottles n - 1 "of beer on the wall" crlf
]]</syntaxhighlight>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <Prout <Verses 99>>;
};
 
Verses {
'-'1 = ;
s.1 = <Verse s.1>
<Verses <- s.1 1>>;
};
 
Verse {
s.1 = <Bottles s.1> ' of beer on the wall,\n'
<Bottles s.1> ' of beer,\n'
<ThirdLine s.1> '\n'
<Bottles <- s.1 1>> ' of beer on the wall!\n\n';
};
 
Bottles {
'-'1 = '99 bottles';
0 = 'No more bottles';
1 = '1 bottle';
s.1 = s.1 'bottles';
};
 
ThirdLine {
0 = 'Go to the store and buy some more,';
1 = 'Take it down and pass it around,';
s.1 = 'Take one down and pass it around,';
};</syntaxhighlight>
 
=={{header|Relation}}==
Line 11,716 ⟶ 11,901:
</syntaxhighlight>
 
=={{header|RPL}}==
≪ " bottles" " of beer" " on the wall" "Take one down and pass it around,"
→ n b of on take
≪ n 1 '''FOR''' j
j →STR b + of + DUP on + "," + 1 DISP
"," + 2 DISP
take 3 DISP
j 1 ≠ LAST - →STR "No more" IFTE
b +
'''IF''' j 2 == '''THEN''' 1 OVER SIZE 1 - SUB '''END'''
of + on + "." + 4 DISP
-1 '''STEP'''
≫ ≫ '<span style="color:blue">BOB</span>' STO
 
99 <span style="color:blue">BOB</span>
=={{header|RPL/2}}==
===Simple solution===
Line 12,398 ⟶ 12,598:
(v ~~ 0) ifTrue: [ Transcript show: (sr at:4) ; cr. ].
].</syntaxhighlight>
 
 
This version uses Squeak Smalltalk's String >> format: method. and SequencableCollection >> atPin: method
<syntaxhighlight lang="smalltalk">
|bottles plurals |
Transcript clear.
bottles:='{1} bottle{2} of beer on the wall
{1} bottle{2} of beer
Take one down, pass it around
{3} bottle{4} of beer on the wall'.
plurals := #('' 's').
99 to: 1 by: -1 do:[:v |
Transcript show: (bottles format: {(v asString) . (plurals atPin:v) . ((v -1) asString). (plurals atPin:v) }); cr; cr].
 
Transcript show: 'hic!'; cr.
 
</syntaxhighlight>
 
 
This version uses Squeak Smalltalk's String >> asPluralBasedOn: method to handle the plural and singular cases.
<syntaxhighlight lang="smalltalk">
 
| bottles |
Transcript clear.
bottles := '{1} {2} of beer on the wall
{1} {2} of beer
Take one down, pass it around
{3} {4} of beer on the wall'.
99 to: 1 by: -1 do: [:i |
Transcript
show: (bottles format: {
i. 'bottle' asPluralBasedOn: i.
i - 1. 'bottle' asPluralBasedOn: i - 1});
cr; cr].
Transcript show: 'hic!'; cr.
</syntaxhighlight>
 
=={{header|SmileBASIC}}==
Line 13,212 ⟶ 13,448:
 
main = whole_song 99</syntaxhighlight>
 
=={{header|Uxntal}}==
<syntaxhighlight lang="Uxntal">( uxncli 99bottles.rom )
 
|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
 
|0100 ( -> )
#63 &loop
DUP <print-verse>
[ LIT2 0a -Console/write ] DEO
#01 EQUk ?&done
POP #01 SUB
!&loop
&done BRK
 
@<print-verse> ( num -- )
DUP <print-bottle> ;dict/wall <print-string>
DUP <print-bottle> [ LIT2 0a -Console/write ] DEO
;dict/take <print-string>
#01 SUB <print-bottle> ;dict/wall !<print-string>
 
@<print-bottle> ( num -- )
DUP #00 EQU ?&zero
DUP #01 EQU ?&one
<print-dec> ;dict/bottle <print-string>
[ LIT2 "s -Console/write ] DEO
!&end
 
&one ( num -- )
<print-dec> ;dict/bottle <print-string>
!&end
&zero ( num -- )
POP ;dict/no-more <print-string>
;dict/bottle <print-string>
[ LIT2 "s -Console/write ] DEO
( >> )
&end
;dict/of-beer
( >> )
 
@<print-string> ( str -- )
&loop
LDAk .Console/write DEO
INC2 LDAk ?&loop
POP2 JMP2r
 
@<print-dec> ( byte -- )
DUP #64 DIV <print-num>/try
DUP #0a DIV <print-num>/try
( >> )
 
@<print-num> ( num -- )
#0a DIVk MUL SUB
[ LIT "0 ] ADD .Console/write DEO
JMP2r
 
&try ( num -- )
DUP ?<print-num>
POP JMP2r
 
@dict &no-more "No 20 "more $1
&bottle 20 "bottle $1
&of-beer 20 "of 20 "beer 20 $1
&wall "on 20 "the 20 "wall 0a $1
&take "Take 20 "one 20 "down, 20 "pass 20 "it 20 "around 0a $1</syntaxhighlight>
 
=={{header|UTFool}}==
Line 13,567 ⟶ 13,868:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">for (i in 99...0) {
System.print("%(i) bottles of beer on the wall,")
System.print("%(i) bottles of beer,")
System.print("Take one down, pass it around,")
System.print("%(i - 1) bottles of beer on the wall.\n")
}</syntaxhighlight>
 
Line 13,851 ⟶ 14,152:
</syntaxhighlight>
 
 
=={{header|YAMLScript}}==
<syntaxhighlight lang="yaml">
#!/usr/bin/env ys-0
 
# Print the verses to "99 Bottles of Beer"
#
# usage:
# ys 99-bottles.ys [<count>]
 
defn main(number=99):
each [n (number .. 1)]:
say: paragraph(n)
 
defn paragraph(num): |
$bottles(num) of beer on the wall,
$bottles(num) of beer.
Take one down, pass it around.
$bottles(num - 1) of beer on the wall.
 
defn bottles(n):
cond:
n == 0 : 'No more bottles'
n == 1 : '1 bottle'
=> : "$n bottles"
</syntaxhighlight>
 
=={{header|Yorick}}==
3

edits