# 99瓶啤酒[关闭]

65

``````99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.

98 bottles of beer on the wall, 98 bottles of beer.
Take one down and pass it around, 97 bottles of beer on the wall.

97 bottles of beer on the wall, 97 bottles of beer.
Take one down and pass it around, 96 bottles of beer on the wall.

96 bottles of beer on the wall, 96 bottles of beer.
Take one down and pass it around, 95 bottles of beer on the wall.

95 bottles of beer on the wall, 95 bottles of beer.
Take one down and pass it around, 94 bottles of beer on the wall.

....

3 bottles of beer on the wall, 3 bottles of beer.
Take one down and pass it around, 2 bottles of beer on the wall.

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.
Go to the store and buy some more, 99 bottles of beer on the wall.
``````

30

5

Chris Laplante

3

1
@Chris-这将是该SE网站最困难的部分，因为整个过程都是基于创造力的，因为这是编程难题的一半乐趣。最具创意的解决方案并不总是最有效或最短的。
Nick Berardi

2
@尼克：我听到你了。我只是想知道如何根据自己的判断来确定解决方案的创造性？基于选民的？两者都不是特别可靠（无犯罪）。简洁是无可争辩的，例如，没有人可以质疑1字节堆栈溢出代码高尔夫解决方案的“优缺点”。

70

# Perl（410个字符）

[bottles.pl]

```         \$ a =
“ cpuu
\ bmft p
\ bg cff
\ bs“; \$ b
=“ po ui
\ bf xbm
\ bm“; \$ c =”
尤文
\ bof epxo qb
\ btt ju bspvoe“;
\$ a =〜s / \ n //; \$ a =〜
s / \ s + / / g; \$ b =〜
s / \ n //; \$ b =〜
s / \ s + / / g; \$ c =〜
s / \ n //; \$ c =〜
s / \ s + / / g; \$ a =〜
y / bz / az /; \$ b =〜
tr / bz / az /; \$ c =〜
tr / bz / az /; 对于（
\$ d = 100; \$ d> 0; \$ d-）{
打印“ \$ d \$ a \$ b \$ d”
;打印“ \$ a，\ n \$ c，”
;打印（\$ d-1）;打印
“ \$ a \$ b。\ n”;} \$ x =
“ cjc”；\$ y =“ dobbz”;
\$ z =“ com”; print“ \ n”
;打印“-\$ x \ @ \$ y”。
;打印“ \$ z \ n \ n”;

```

1

F. Hauri 2014年

“ rot1”密码，不是我所见过的最好的混淆方法。使用`\b`“删除”不需要的字符也有些令人失望。
primo 2014年

100

## Brainf ***（1,509）

``````    +++           +++           +++           [>+           +++           ++>           +++           +++           <<-
]>+           ++>           +++           >++           +++           +++           ++>           +++           +++
+++>+         +++++         +++++         [>+++         >++++         >++++         <<<-]         >->>+         +>+++
+++++         [>+++         +++++         ++++>         +++++         +++++         ++>++         +++++         +++++
>++++         +++++         +++>+         +++++         +++++         +>+++         +++++         +++++         >++++
+++++         ++++>         +++++         +++++         +++>+         +++++         +++++         ++>++         +++++
++++++>       +++++++       ++++++>       +++++++       +++++++       >++++++       +++++++       +>+++++       +++++++
++>++++       +++++++       +++>+++       +++++++       ++++>++       +++++++       +++++<<       <<<<<<<       <<<<<<<
<-]>+>+       +>++++>       +++++>+       +++++>>       +>+++>+       +++>+++       +++>+++       ++++>>+       +>+++>+
+++>+++++     >+++++++<     <<<<<<<<<     <<<<<<<<<     <<<<[>[<<     <.>.>>>>.     >>>>>.>>>     >>>>>>.>>     >>..<<<<<
<.<<<<<.>>>   >>>>>>>.<<<   <<<<<<<<<<<   <<<.>>>>>>>   >>>>>>>.<<<   <<<.<<<<<<<   <.>>>>>.>>.   .>>>>>>>>>.   <<<<<<<<<<<
<<<<<.>>>>>   >>>>>>>>>.<   .<<<<<<<<<<   <<<.>>>>>>>   >>>>>>>>>>>   .<<<<<<<<<.   <<.<<<<<<<.   >>>>>>>>>>>   >>>>>>>>>.<
<<<<<<<<<<<   <<<<.>>>>>>   >>..<<<<<<<   <<<<.<.<<<<   <.>.>>>>.>>   >>>.>>>>>>>   >>.>>>>..<<   <<<<.<<<<<.   >>>>>>>>>>.
<<<<<<<<<<<   <<<<<<.>>>>   >>>>>>>>>>.   <<<<<<.<<<<   <<<<.>>>>>.   >>..>>>>>>>   >>.<<<<<<<<   <<<<<<<.<.>   >>>>>>>>>>>
>>>>>>.<<<<   <<<<<<<<<<.   >>>>>>>.<<<   <.<<<<<<<.>   >>>>>>>>>>>   >>.<.<<<<<<   .<<<<<<<.>>   >>>>.>>>>>>   >>.>>>>>>.<
<<<<<<.<<<<   <<<<<<<<<.>   >>>.>>>>>>>   >>.<<<<<<<.   <<<<<<.>>>>   >>>>>>>>>>>   .<<<<<<<<<<   <.>>>>>>>>>   >>>>..<<<<<
<<<<<<<<<<<   <.>>>>>>>>>   >.>>>>>>>>.   <<<<<<<<<<<   <<<<<<<.>>>   >.>>>>>>>>>   >>>.<<.>>>>   >.<<<<<<.<<   <<<<<.<<<<<
.<.<<<<<.>-   .>>>>.>>>>>   .>>>>>>>>>.   >>>>..<<<<<   <.<<<<<.>>>   >>>>>>>.<<<   <<<<<<<<<<<   <<<.>>>>>>>   >>>>>>>.<<<
<<<.<<<<<<<   <.>>>>>.>>.   .>>>>>>>>>.   <<<<<<<<<<<   <<<<<.>>>>>   >>>>>>>>>.<   .<<<<<<<<<<   <<<.>>>>>>>   >>>>>>>>>>>
.<< < <<<     <<< . <<.     <<< < <<<     .>> > >>>     >>> > >>>     >>> > >>>     .<< < <<<     <<< < <<<     <<< . >>>
>> >>>.       .<<< <<       <<<< <.       << . <<       -]+ +++       ++ + ++       << + ++       ++ + ++       +<->>-]
``````

9

Joe Z.

Cyoce

99

## 功能

``````                                            ╓┬────╖
╔════╗  ┌───╖                          ╟┘99b ║
║ −1 ╟──┤ + ╟──┐                       ╙──┬──╜
╚════╝  ╘═╤═╝  ├──────────────────────────┴─────────────────────────────┐
╔════╗  ┌─┴─╖  │  ╔════════════════════════════════════════════════════╗│
║ 99 ╟──┤ ? ╟──┘  ║ 93438979891487426396059469986395555362079573844971 ║│
╚════╝  ╘═╤═╝     ║ 71377306928718494179034460561943201885027745835961 ║│
┌──┴───╖   ║ 98129935108241412387473531261660077880505710501626 ║│
╔════╗  │ 99bp ║   ║ 32694396343717333192558234646820019070451056711    ║│
║ 99 ║  ╘══╤═══╝   ╚══════════════════════════╤═════════════════════════╝│
╚═╤══╝   ┌─┴─╖                       ┌───╖  ┌─┴─╖  ╔═════════════════╗   │
┌──┴──╖   │ ‼ ╟───────────────────────┤ ‼ ╟──┤ ? ╟──╢ 445551776368547 ║   │
│ 99b ║   ╘═╤═╝┌─────────────────────┐╘═╤═╝  ╘═╤═╝  ║ 925186328623383 ║   │
╘══╤══╝     │  │╔═══════════════════╗│  │      │    ║ 851314944882510 ║   │
│        │  │║ 15177132563375318 ║│  │      │    ║ 812246570019017 ║   │
╔════════╗    │  │║ 07655616350359109 ║│  │      │    ║ 240477365113929 ║   │
║ 318287 ║    │  │║ 82597577171382437 ║│  │      │    ║ 659548419629671 ║   │
║ 023073 ║    │  │║ 18150105146396039 ║│  │      │    ║ 952755268258505 ║   │
║ 603558 ║    │  │║ 2022986808360992  ║│  │      │    ║ 759402210908648 ║   │
║ 743780 ║    │  │╚══════════╤════════╝│  │      │    ║ 737406010882693 ║   │
║ 068900 ║    │  │         ┌─┴─╖ ┌───╖ │  │      │    ║ 018745757193818 ║   │
║ 028319 ║    │  │         │ ‼ ╟─┤ ‼ ╟─┘  │      │    ║ 597439618635403 ║   │
║ 948400 ║    │  │         ╘═╤═╝ ╘═╤═╝    │      │    ║ 821854707881243 ║   │
║ 620075 ║    │  │         ┌─┴─╖   │    ┌─┴─╖    │    ║ 92049082452     ║   │
║ 955580 ║    │  └─────┬───┤ ‼ ╟────────┤ ‼ ║    │    ╚═════════════════╝   │
║ 347161 ║    │        │   ╘═══╝┌──────┐╘═╤═╝    └─────────────┐            │
║ 651333 ║    │   ╔═══╗│┌──────╖│╔════╗│ ╔╧═════════╗          │            │
║ 590970 ║    │   ║ 0 ║└┤ 99bp ╟┘║ −1 ║└┐║ 20971566 ║          ├────────────┘
║ 678045 ║    │   ╚══╤╝ ╘══════╝ ╚══╤═╝ │╚══════════╝          │
║ 336290 ║  ┌─┴─╖  ┌─┴─╖  ┌─────╖  ┌┴──╖├──────────────────────┘
║ 721824 ╟──┤ ‼ ╟──┤ ? ╟──┤ 99b ╟──┤ + ║│
╚════════╝  ╘═══╝  ╘═╤═╝  ╘═════╝  ╘═╤═╝│    ╓┬──────╖
└───────┬───────┘  │    ╟┘ 99bp ║
└──────────┘    ╙───┬───╜
┌────────────────────────────────────────────────┴──────────────┐
│╔══════════════════════════════════════════╗╔═══════════╗      │
│║ 8592134145756414358602136806465202028576 ║║ 232783950 ║      │
│╚══════════════════════════════╤═══════════╝╚╤══════════╝      │
│               ┌───╖  ╔═══╗  ┌─┴─╖  ┌───╖  ┌─┴─╖  ┌─────────╖  │
└───────────────┤ = ╟──╢ 1 ║  │ ‼ ╟──┤ ‼ ╟──┤ ? ╟──┤ int→str ╟──┴┐
╘═╤═╝  ╚═══╝  ╘═╤═╝  ╘═╤═╝  ╘═╤═╝  ╘═════════╝   │
╔═══╗  ┌─┴─╖         ┌─┴─╖    │      └──────────────────┘
║ 0 ╟──┤ ? ╟─────────┤ ‼ ╟──┐
╚═══╝  ╘═╤═╝         ╘═══╝  │
╔════╧╗╔════════════════╧════════════════════════════════╗
║ 115 ║║ 20338288213193790107412311132593873016630280224 ║
╚═════╝╚═════════════════════════════════════════════════╝
``````

1

gyurisc 2011年

1

1

ML 2015年

56

# jQuery + FireBug控制台

``````\$('code:first').text()
``````

;）

2

JiminP 2011年

2

Spoike 2011年

2012年

1
@JiminP不幸的是，考虑到答案顺序如何随时间变化，这并不是一个稳定的选择器（实际上，它不再起作用）。
Muhd 2013年

2

24

HQ9 +（1个字符）

``````9
``````

13

Mateen Ulhaq 2011年

1
@muntoo我不确定HQ9 + B是否已完成演奏。.命令B轮询键盘输入并将其评估为Brainfuck，因此它是带有调性Brainfuck解释器的HQ9 +。即HQ9 + B中的程序“ B”将轮询stdin直到获得！（或EOF）并将其解释为Brainfuck。
Sylwester 2014年

20

``````using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _99Bottles
{
class Program
{
static void Main(string[] args)
{
PrintSong(99);
}

static void PrintSong(int bottleCount)
{
Func<int, string> sOrBlank = howMany => howMany > 1 ? "s" : "";

PrintBottles(howManyBottles =>
{
Console.WriteLine("{0} bottle{1} of beer on the wall, {0} bottle{1} of beer.", howManyBottles, sOrBlank(howManyBottles));
if (howManyBottles > 1)
{
Console.WriteLine("Take one down and pass it around, {0} bottle{1} of beer on the wall.", --howManyBottles, sOrBlank(howManyBottles));
}
else
{
Console.WriteLine("Go to the store and buy some more, 99 bottles of beer on the wall.", --howManyBottles);
}
},
bottleCount);
}

static void PrintBottles(Action<int> printBottles, int count)
{
printBottles(count);

if (count > 1)
{
PrintBottles(printBottles, --count);
}
}
}
}
``````

11
+1成为Perl海洋中的另一只C型牺牲羔羊。
Glenn Nelson

Nellius

2
@Nellius你甚至什么`ilivewithian`他的代码之前说的吗？
Daniel Standage

1
@Daniel是的，这意味着他认为代码中的所有内容都是必需的。如果只是开个玩笑，就不应该被这么大地投票。它不短，创新，高效，甚至不高明。
Nellius 2011年

@Nellius这并不是认真的竞争者，在任何方面都没有这个好的代码。我敢肯定，它可以减少，提高效率并大幅度改善。

18

# C

``````#define BOTTLES(n) n " bottles of beer"
#define BOTTLE "1 bottle of beer"
#define OTW " on the wall, "
#define TAKE "Take one down, pass it around, "
#define STOP "."
#define NL "\n"

#define LINE1(n) BOTTLES(n) OTW BOTTLES(n) STOP NL
#define LINE1A BOTTLE OTW BOTTLE STOP NL
#define LINE2(n) TAKE BOTTLES(n) STOP NL
#define LINE2A TAKE BOTTLE STOP NL

#define MIDDLEPART(n) LINE2(n) NL LINE1(n)
#define MIDDLELAST LINE2A NL LINE1A

#define EIGHT_TO_TWO(S, M) M(S "8") M(S "7") M(S "6") M(S "5") M(S "4") M(S "3") M(S "2")
#define EIGHT_TO_ONE(S, M) EIGHT_TO_TWO(S, M) M(S "1")
#define EIGHT_TO_TWO_AGAIN(S, M) M(S "8") M(S "7") M(S "6") M(S "5") M(S "4") M(S "3") M(S "2")
#define EIGHT_TO_ONE_AGAIN(S, M) EIGHT_TO_TWO_AGAIN(S, M) M(S "1")
#define NINE_TO_TWO(S, M) M(S "9") EIGHT_TO_TWO(S, M)
#define EIGHT_TO_ZERO(S, M) EIGHT_TO_ONE(S, M) M(S "0")
#define NINE_TO_ZERO(S, M) M(S "9") EIGHT_TO_ZERO(S, M)

#define NINETIES EIGHT_TO_ZERO("9", MIDDLEPART)
#define NTIES(n) NINE_TO_ZERO(n, MIDDLEPART)
#define EIGHTIES_TO_TENS EIGHT_TO_ONE_AGAIN("", NTIES)
#define NAUGHTIES NINE_TO_TWO("", MIDDLEPART)

#define SONG LINE1("99") NINETIES EIGHTIES_TO_TENS NAUGHTIES MIDDLELAST LINEX

#include <stdio.h>

int main()
{
puts(SONG);
return 0;
}``````

1

TomPažourek2014年

1
@tomp时间高效，可执行文件大小效率非常低：)
Seequ 2014年

14

C＃（312个 310 304字符）

``````class P{static void Main(){string b=" bottle",w=" on the wall",o=" of beer",p=".\n",s="s";for(int i=99;i>0;i--)System.Console.Write(i+b+(i>1?s:"")+o+w+", "+i+b+(i>1?s:"")+o+p+(i>1?"Take one down and pass it around, "+(i-1)+b+(i-1>1?s:"")+o+w+p+"\n":"Go to the store and buy some more, "+99+b+s+o+w+p));}}
``````

1

jcolebrand 2011年

12

## C＃

``````using System;
using System.Linq;

class Program
{
static void Main()
{
Console.WriteLine(string.Join(Environment.NewLine, Enumerable.Range(0, 100).Select(i =>
string.Format(
string.Format(
"{0} {1} {{3}} {{4}},{{9}}{0} {1} {{3}}.{{9}}{2},{{9}}{3} {4} {{3}} {{4}}.{{9}}",
i == 99 ? "{0}" : "{7}",
i == 98 ? "{1}" : "{2}",
i == 99 ? "{6}" : "{5}",
i == 98 ? "{0}" : "{8}",
i == 97 ? "{1}" : "{2}"
),
"No",
"bottle",
"bottles",
"of beer",
"on the wall",
"Take one down, pass it around",
"Go to the store, buy some more",
99 - i,
(198 - i) % 100,
Environment.NewLine
))));
}
}
``````

11

``````perl -e '\$i=99;while(\$i>1){print("\$i bottles of beer on the wall, \$i bottles of beer.\nTake one down and pass it around, ".--\$i." bottles of beer on the wall\n\n");}print("1 bottle of beer on the wall, 1 bottle of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n");'
``````

11

``````(&)=(++)
b 1=" bottle"
b _=b 1&"s"
w=" on the wall"
p n=show n&b n&" of beer"
f n=putStrLn\$p n&w&","&p n&".\n"&c(n-1)
c 0="Go to the store and buy some more, "&p 99&w&"."
c n="Take one down and pass it around, "&p n&w&"\n"
main=mapM f[99,98..1]
``````

11

## Windows PowerShell（198）

``````filter b{"\$_ bottle\$('s'*!!--\$_) of beer"}(99..1|%{(\$_|b)+(\$w=' on the wall')+", \$(\$_|b)."
"Take one down and pass it around, \$(--\$_|b)\$w.
"})[0..196]
"Go to the store and buy some more, \$(99|b)\$w."
``````

Rebmu博士

Iszi

`filter b{"\$_ bottle\$('s'*!!--\$_) of beer"}(99..1|%{(\$_|b)+(\$w=' on the wall')+", \$(\$_|b).";"Take one down and pass it around, \$(--\$_|b)\$w. "})[0..196];"Go to the store and buy some more, \$(99|b) \$w."`解决该问题。总计199个字符。（在此`\$w`之前添加一个换行符`"`
Iszi 2013年

10

## 卷曲19个字符

（需要互联网连接）

``````curl -L j.mp/eGv9K5
``````

7

marcog 2011年

8

Alexandru

3

pimvdb

1

9

``````#!/usr/bin/perl
#      ^
#      |
#      |
# That's the Perl interpreter.
# You might need to change this line based on

# Pragmas for debugging!
use strict;
use warnings;

# Library dependencies...none! lolz

# Main implementation
LOOP: while( \$number_of_bottles_of_beer_on_the_wall > 0 )
{
printf( "%d bottles of beer on the wall, %d bottles of beer\n",
\$number_of_bottles_of_beer_on_the_wall,
\$number_of_bottles_of_beer_on_the_wall,                  );

if( \$number_of_bottles_of_beer_on_the_wall > 1 )
{
\$number_of_bottles_of_beer_on_the_wall -= 1;
printf( "Take one down and pass it around, %d bottles of beer on the wall.\n\n",
\$number_of_bottles_of_beer_on_the_wall,                               );
}
else
{
printf( "Go to the store and buy some more, %d bottles of beer on the wall\n",
99                                                                     );
last LOOP;
}
}
``````

nyuszika7h 2014年

1
@ nyuszika7h有见地的批评！;）
Daniel Standage 2014年

8

# 的JavaScript（216 228 215）

``````for(a=99,c=" on the wall";a;)document.write((d=eval(b="(a||99)+' bottle'+(a-1?'s':'')+' of beer'"))+c+", "+d+".<br>"+(--a?"Take one down and pass it around, ":"Go to the store and buy some more, ")+eval(b)+c+".<p>")
``````

Yahel 2011年

aaaaaaaaaaaaaa

MARÖrlygsson

@MárÖrlygsson欢迎来到站点。在开篇文章中定义了此挑战的歌词。
aaaaaaaaaaaaaa 2014年

7

C

``````// Time to go to the shop and get some beer
//
//
//
//
// #####.#####.#####.#####.#####.#####.#####
// ##.#####.#####.#####.#####.#####.#####.##
// #####.#####.#####.#####.#####.#####.#####
// ##.#####.#####.#####.#####.#####.#####.##

char *z [] = {
"void l(char *s,int b){int i;printf(\"// \");for(i=0;i<b;++i)printf(s);",
"printf(\"\\n\");}\nint main(int argc, char *argv[]){\nint i,j,k,x=%d;",
"char*p;\nif(!x&&argc==2)x=atoi(argv[1]);\nif(!x){printf(\"// Time to ",
"go to the shop and get some beer\\n//\\n//\\n//\\n//\\n\");k=7;\n",
"}else{printf(\"// %%d bottles of beer on the wall, %%d bottles of beer",
".\\n\",x,x);printf(\"// Take one down and pass it round, \");\n",
"if(x>1)printf(\"%%d bottles of beer on the wall.\\n//\\n\",x-1);\n",
"else printf(\"no more bottles of beer on the wall.\\n//\\n\");\n",
"k=x>2?x:2;l(\"  ^   \",x);l(\" / \\\\  \",x);l(\"/   \\\\ \",x);",
"l(\"|   | \",x);l(\"|Duf| \",x);l(\"|   | \",x);l(\"----- \",x);}\n",
"for(i=0;i<4;++i){\nprintf(\"// %%s\", i&1 ? \"##.\" : \"\");\n",
"for(j=i&1;j<k;++j)\nprintf(\"%%s#####\",j!=(i&1)?\".\":\"\");\n",
"printf(\"%%s\\n\",i&1?\".##\":\"\");}\nprintf(\"\\nchar *z [] = {\\n\");\n",
"for(i=0;i<sizeof z/sizeof z[0];++i){\nprintf(\"\\\"\");\n",
"for(p=z[i];*p;++p)\nswitch (*p){\ncase '\\n':printf(\"\\\\n\");break;\n",
"case '\\\\':printf(\"%%c%%c\",92,92);break;\n",
"case '%%':printf(\"%%c\",37);break;\ncase '\"':printf(\"%%c%%c\",92,'\"');break;\n",
"default:printf(\"%%c\", *p);break;}\nprintf(\"\\\",\\n\");}\n",
"printf(\"};\\n\");\nfor(i=0;i<sizeof z/sizeof z[0];++i)\n",
"printf(z[i],x?x-1:0);}\n",
};
void l(char *s,int b){int i;printf("// ");for(i=0;i<b;++i)printf(s);printf("\n");}
int main(int argc, char *argv[]){
int i,j,k,x=0;char*p;
if(!x&&argc==2)x=atoi(argv[1]);
if(!x){printf("// Time to go to the shop and get some beer\n//\n//\n//\n//\n");k=7;
}else{printf("// %d bottles of beer on the wall, %d bottles of beer.\n",x,x);printf("// Take one down and pass it round, ");
if(x>1)printf("%d bottles of beer on the wall.\n//\n",x-1);
else printf("no more bottles of beer on the wall.\n//\n");
k=x>2?x:2;l("  ^   ",x);l(" / \\  ",x);l("/   \\ ",x);l("|   | ",x);l("|Duf| ",x);l("|   | ",x);l("----- ",x);}
for(i=0;i<4;++i){
printf("// %s", i&1 ? "##." : "");
for(j=i&1;j<k;++j)
printf("%s#####",j!=(i&1)?".":"");
printf("%s\n",i&1?".##":"");}
printf("\nchar *z [] = {\n");
for(i=0;i<sizeof z/sizeof z[0];++i){
printf("\"");
for(p=z[i];*p;++p)
switch (*p){
case '\n':printf("\\n");break;
case '\\':printf("%c%c",92,92);break;
case '%':printf("%c",37);break;
case '"':printf("%c%c",92,'"');break;
default:printf("%c", *p);break;}
printf("\",\n");}
printf("};\n");
for(i=0;i<sizeof z/sizeof z[0];++i)
printf(z[i],x?x-1:0);}
``````

nderscore 2014年

6

# Java语言（285）

``````b=' of beer on the wall';n=100;while(--n>1)if(n>1)print(n+" bottles"+b+', '+n+" bottles of beer.\nTake one down and pass it around, "+(n-1)+' bottle'+(n-1>1?'s':'')+b+'.\n\n');print("1 bottle"+b+", 1 bottle of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.")
``````

8

Chris Laplante

10
Javascript不提供任何标准的输出字符串的方法，如果您在浏览器中运行它，则它没有打印功能，如果您在Rhino中运行它，则可以。

2
`document.writeln`作品。

4
...对于浏览器

5
JavaScript的IO具有：`alert`作为输出，`prompt`作为变量输入和`confirm`作为布尔输入。它们会影响到UI，但它们是标准的阻塞IO功能。`alert`并且`print`长度相同，因此您的代码应该大致相等。
zzzzBov

6

# 计划（270）

``````(let l((i 99))(let((b" bottle")(c" on the wall")(d"Take one down and pass it around,")(e".\n")(f", ")(g" of beer"))(if(= i 1)(map display`(1,b,g,c,f,1,b,g,e"Go to the store and buy some more, 99",b,c,e))(begin(map display`(,i,b,g,c,f,i,b,e,d,i,b,c,e"\n"))(l(-1+ i))))))
``````

``````    (let l ((i 99))
(let ((b" bottle")
(c" on the wall")
(d"Take one down and pass it around, ")
(e".\n")
(f", ")
(g" of beer"))
(if (= i 1)
(map display`(1 ,b ,g ,c ,f ,1 ,b ,g ,e
"Go to the store and buy some more, 99" ,b ,c ,e))
(begin (map display `(,i ,b ,g ,c ,f ,i ,b ,e ,d ,i ,b ,c ,e "\n"))
(l (-1+ i))))))
``````

6

# Python-很多

``````print"""99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.

98 bottles of beer on the wall, 98 bottles of beer.
Take one down and pass it around, 97 bottles of beer on the wall.

97 bottles of beer on the wall, 97 bottles of beer.
Take one down and pass it around, 96 bottles of beer on the wall.

96 bottles of beer on the wall, 96 bottles of beer.
Take one down and pass it around, 95 bottles of beer on the wall.

95 bottles of beer on the wall, 95 bottles of beer.
Take one down and pass it around, 94 bottles of beer on the wall.

....

Ok, this is stupid. First of all, what the brainfuck are the bottles doing on the wall? They're not spiders nor picture frames. And how are they sitting on the wall?

94 bottles of beer on the wall, 9.. oops, they fell down. 94 bottles of beer on the floor, 94 bottles of beer.

Second.. who the HQ9+ wants to keep track? I think I lost count after drinking the 2nd one...

Take one ... um... up, and pass it around,  .....  er.. a lot of bottles of beer still on the floor.

Fourthly, what's with this passing around scheme? They're not j..I mean letters, yeah, or boxes of chocolate. We all can just take one and drink it. It's healthier too.

A pile of bottles of beer on the floor, a pile of bottles of beer.
Everyone take one up and drink it, still a whole bunch of bottles of beer on the floor.

Um.. seventhly, are we really that many in this assembly that we can finish 200 or however many bottles we had in the beginning? Without passing out?

Go to the store and buy some more

Yeah and who's gonna pay for it? Definitely not me. And how are you going to bring 300 bottles back from the store?
In your car? Buddy, you're so drunk, you can't even C anything. Go home dude, go home. Take a cab."""
``````

5

## 蟒蛇（318）

``````exec'eJxtjrFqwzAQQHd/xVVgLCVqSbq5RHO2TtlcgyX7Qk3luyAphP59ZA0thGzi9O7es0bUERyn5DE/+AwOMdTxi0TljLeLmyzQB4GlaaCBg/hkWDigqMb/76aZz0CHHaCPCLaWTpLSTWw2kl7MXmkBTJC+EW7Wey3U9hmzzqU42R/MNMLEt6KFi40R5gQ28JUmndO0ODIkLhdjyjWFc9dfiLxg6Vsx1ZExu36Vddn2miVD2w59R4d9/6d+f8h7Wze3Y+GrS5gpwSjbVlV3Y1BZCg=='.decode('base64').decode('zip')
``````

ixtmixilix 2012年

5

5

## Rebmu -167个字符

`M N 99 Bdz[cb[n{ bottle}egN 1{s}{}{ of beer}]]loN[cb[b W{ on the wall}C{, }b P{.}lfEZ--n[Nm{Go to the store and buy some more}]{Take one down and pass it around}cBwPlf]]`

``````m: n: 99

b: does [
combine [n { bottle} either n > 1 {s} {} { of beer}]
]

loop n [
print combine [
b w: { on the wall} c: {, } b p: {.} newline

either 0 == -- n [
n: m
{Go to the store and buy some more}
] [
{Take one down, and pass it around}
]

c b w p newline
]
]
``````

GitHub上有注释的源代码

5

## PHP：285个240 233 231特性

``````\$i=99;\$b=" bottles of beer";\$o=" bottle of beer";\$c=" on the wall";while(\$i>1){echo"\$i\$b\$c, \$i\$b.\nTake one down and pass it around, ".--\$i.((\$i>1)?\$b:\$o).\$c.".\n\n";}echo"\$i\$o\$c, \$i\$o.\nGo to the store and buy some more, 99\$b\$c.";
``````

4

## Python，241个字符

``````s=""
i=99
b="%d bottl%s of beer"
w=" on the wall"
t="Take one down and pass it around, "
p=q="es"
while i:s+=b%(i,p)+w+", "+b%(i,p)+".\n";i-=1;p=p[:i];s+=t+b%(i,p)+w+".\n\n"
print s[:-64]+"Go to the store and buy some more, "+b%(99,q)+w+"."
``````

4

## Ruby，274个字节

``````o =" bottles of beer";w=" on the wall";t="Take one down and pass it around, ";s=" bottle of beer"
99.downto(3){|b|puts"#{b}#{o+w}, #{b}#{o}.\n#{t}#{b-1}#{o+w}.\n\n"}
puts"2 #{o+w}, 2 #{o}.\n#{t}1#{s}#{w}.\n\n1#{s+w}, 1#{s}.\nGo to the store and buy some more, 99#{o+w}."
``````

4

# C＃（299个字符）

``````using System;class D{static void Main(){string a="s",z="",w=" on the wall",q=", ",p=".\n",b=" bottle",c=" of beer";for(int O=99;O>=1;)Console.WriteLine(O+b+(O>1?a:z)+c+w+q+O+b+(O>1?a:z)+c+p+(--O>0?"Take one down and pass it around, "+O:"Go to the store and buy some more, 99")+b+(O==1?z:a)+c+w+p);}}
``````

1

Nellius 2011年

@Nellius〜更正〜并感谢您具有竞争力的代码，我重新访问了我的代码，并删除了一些单个插入块，并减少了我自己代码中的一些先前存在的常量。现在顺利降至300以下。
jcolebrand

Tester101

@ Tester101〜好电话。还没考虑！
jcolebrand

4

## JavaScript（7个函数）

``````function firstUpper(s) {
return s.slice(0, 1).toUpperCase() + s.slice(1);
}

function bottles(x) {
return (x || "no more") + " " + (x == 1 ? "bottle" : "bottles") + " of beer";
}

function wall(x) {
return bottles(x) + " on the wall";
}

function line1(x) {
return wall(x) + ", " + bottles(x) + ".";
}

function line2(x, max) {
return (x ? "take one down and pass it around, " + wall(x - 1) : "go to the store and buy some more, " + wall(max)) + ".";
}

function verse(x, max) {
return [line1(x), line2(x, max)].map(firstUpper).join("\n") + "\n\n";
}

function song(max) {
var text = "";
for(var x = max; x >= 0; x--) {
text += verse(x, max);
}
return text;
}

print(song(99));
``````

4

# 去（263）

``````package main
import "fmt"
func main(){b,i,e,r:=fmt.Println,99,"bottles","of beer on the wall"
for i>0{b(i,e,r+",",i,e,r[:7]+".")
if i--;i<2{e=e[:6]}
if i>0{b("Take one down and pass it around,",i,e,r+`.
`)}}
b("Go to the store and buy some more,",99,e+"s",r+".")}
``````

3

## PHP-252个字节

``````\$a=" bottles of beer";\$b=str_replace("s","",\$a);\$c=" on the wall";for(\$i=98;\$i;)echo(\$j=\$i+1).\$a.\$c.", ".\$j.\$a.".
Take one down and pass it around, ".\$i.(\$i-->1?\$a:\$b).\$c.".

";echo"1".\$b.\$c.", 1".\$b.".
Go to the store and buy some more, 99".\$a.\$c.".";
``````

3

## 红宝石1.9.2p136：223

``````b="%d bottle%s of beer"
w=' on the wall'
99.downto(1){|z|s=b%[z,z>1?'s':'']
puts s+w+", "+s+".
"+(z>1?"Take one down and pass it around, "+b%[z-1,z>2?'s':'']+w+".

" :'Go to the store and buy some more, '+b%[99,'s']+w+".")}
``````

3

# （Oracle）SQL

``````WITH
bottles AS (
SELECT LEVEL - 1 AS bottle
FROM dual
CONNECT BY LEVEL <= &number_of_bottles + 1
),
fragments AS (
SELECT
'no more ' AS none,
'bottles of beer' AS supply,
' on the wall' AS wall,
'Take one down and pass it around' AS drink,
'Go to the store and buy some more' AS refill,
CHR(13) || CHR(10) AS newline
FROM dual
),
combined AS (
SELECT
b.bottle,
DECODE(
b.bottle,
1, b.bottle || ' ' || REPLACE(f.supply, 's'),
0, f.none || f.supply,
b.bottle || ' ' || f.supply
) AS supply
FROM bottles b
CROSS JOIN fragments f

),
two_lines AS (
SELECT LEVEL AS line
FROM dual
CONNECT BY LEVEL <= 2
)
SELECT
CASE l.line
WHEN 1 THEN REPLACE(c1.supply, 'n', 'N') || f.wall || ', ' || c1.supply || '.'
WHEN 2 THEN DECODE(b.bottle, 0, f.refill, f.drink) || ', '  || c2.supply || f.wall || '.'
END AS song
FROM bottles b
LEFT JOIN combined c1 ON (c1.bottle = b.bottle)
LEFT JOIN combined c2 ON (c2.bottle = DECODE(b.bottle - 1, -1, &number_of_bottles, b.bottle - 1))
CROSS JOIN two_lines l
CROSS JOIN fragments f
ORDER BY
b.bottle DESC,
l.line;
``````