“ 99瓶啤酒”


71

编写一个程序,以尽可能少的字节将歌词输出到99瓶啤酒。

歌词:

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.

规则:

  • 您的程序必须登录到STDOUT或可接受的替代方法,或者从函数返回(带或不带尾随换行符)。
  • 您的程序必须是完整的,可运行的程序或功能。
  • 允许使用专门针对此挑战提交0字节答案的语言,但并不是特别有趣。

    请注意,必须有一个解释器,以便可以测试提交。允许(甚至鼓励)自己为以前未实现的语言编写此解释器。

  • 这与HQ9 +或99的输出不同。用这些语言编写的所有答案都将被删除。

因为这是一个目录挑战,所以这不是要找到具有最短解决方案的语言(有些地方空程序可以解决问题),而是要找到每种语言的最短解决方案。因此,没有答案将被标记为已接受。

目录

这篇文章底部的Stack Snippet会根据答案a)生成目录,a)作为每种语言最短解决方案的列表,b)作为整体排行榜。

为确保您的答案显示出来,请使用以下Markdown模板以标题开头。

## Language Name, N bytes

N您提交的文件大小在哪里。如果您提高了分数,则可以通过打败旧分数保持标题。例如:

## Ruby, <s>104</s> <s>101</s> 96 bytes

如果要在标头中包含多个数字(例如,因为您的分数是两个文件的总和,或者您想单独列出解释器标志罚分),请确保实际分数是标头中的最后一个数字:

## Perl, 43 + 2 (-p flag) = 45 bytes

您还可以将语言名称设置为链接,然后该链接将显示在代码段中:

## [><>](http://esolangs.org/wiki/Fish), 121 bytes


13
谁对此投票否决,另一个是一场人气竞赛……
TheDoctor 2015年

21
这是“ 创建HQ9 +口译员”高尔夫的子任务。
Geobits,2015年

4
@CᴏɴᴏʀO'Bʀɪᴇɴ我还没有VTCd,仍在决定我对此有何看法。无论哪种方式,我都认为可以直接复制/粘贴来自对方的一些答案(或来自对方的摘录),同时保持竞争力,这是对重复性的通常测试。
Geobits,2015年

13
请注意,Quartata几周前已经对99BB目录进行了沙箱存储,并计划将其发布。
Alex A.

13
@GamrCorps挑战开始后,请不要不必要地更改规则。输出中的任何字符都不应该是可选的。
feersum

Answers:


43

C#,285 298 289个字节

(我第一次尝试Code打高尔夫球...)

class d{static void Main(){for(int b=99;b>0;)System.Console.Write("{0}{6}{1}{2}, {0}{6}{1} of beer. {3}, {4}{6}{5}{2}.{7}",b,b==1?"":"s"," of beer on the wall",b==1?"Go to the store and buy some more":"Take one down and pass it around",b==1?99:b-1,b==2?"":"s"," bottle",b--<2?"":"\n\n");}}

有点不满意:

class d{
    static void Main(){
        for(int b = 99; b > 0;){
            System.Console.Write("{0}{6}{1}{2}, {0}{6}{1} of beer.\n{3}, {4}{6}{5}{2}.{7}", b, b==1 ? "" : "s", " of beer on the wall", b == 1 ? "Go to the store and buy some more" : "Take one down and pass it around", b == 1 ? 99 : b-1, b== 2 ? "" : "s", " bottle", b--<2 ? "" : "\n\n");
        }
    }
}

10
提示-使用var代替字符串:)
Belfield

2
" bottle"用格式参数替换了2个字节,虽然我确定有更好的方法,但有3个瓶子实例伤害了我的眼睛……
Sven

4
b==1可以替换为b<2
LegionMammal978

2
您的for循环可以这样写for(int b = 100; b--> 1;)
Yassin Hajaj 2015年

2
然后,也许我们应该等待挑战作者决定是否允许尾随换行符。
Florian Bach

31

摩托罗拉MC14500B机器代码,46612字节

由于篇幅原因,我无法在此处发布程序。但是,可以在这里以十六进制形式在这里找到,而在二进制(以0s 填充)中可以找到它。


这是Motorola MC14500B机器代码中最短的程序。它仅由1000100189分别)组成;每个输出位一个操作码。

它使用93,224个半字节操作码,并一次输出一位歌词。这是唯一可能的输出方法。

对于那些感兴趣的人,输出将到达I / O引脚的引脚3(共16个)。


说明

8    Store the register's value
9    Store the logical complement of the register's value

寄存器从开始0


密码琐事

  • 十六进制是93224 8秒和9悠久。

  • 二进制为745792个1S和0悠久。

  • 我使用下面的Python 2代码生成代码。0二进制和1十六进制的输入。

    a,b=["8","9"]if input()else["00001000","00001001"]
    f="""99 Bottles of Beer lyrics"""
    print''.join(b if int(i)else a for i in''.join((8-len(bin(i)[2:]))*'0'+bin(i)[2:]for i in bytearray(f)))

4
请告诉我,如果没有某种字符串生成器,您不仅会把所有内容写完...:c
Addison Crump 2015年

1
参见新的“代码琐事”部分:P @VoteToClose
Zach Gates

链接已断开:(
ETHproductions 2015年

我回到家后会修复它。抱歉):@ETHproductions
Zach Gates

28

Vitsy,0字节



严重的是我什么都没有。(@Mego,我很抱歉。

在线尝试!(只需点击“运行”)


7
o_o我需要一些简单的东西以零字节的形式来做:P
Conor O'Brien

4
@CᴏɴᴏʀO'Bʀɪᴇɴ我想你的意思是,“我需要一些有用的东西来使Simplex以零字节进行处理。”
马丁·恩德

3
@VoteToClose-这是如何工作的?老实说我不知道​​,我不是打高尔夫球的人,但是我很喜欢来到这里,看到人们和语言做到这一点。但是我无法理解这一点。+1,因为它看起来令人印象深刻!
乔尼2015年

1
@Jonnny 单击此处查看解释器的文件处理程序。文件处理程序将看到文件包含零字节,如果是,则打印出歌词。c:
Addison Crump 2015年

1
@Jonnny是的-这项工作仍在进行中,有一天会比“认真”做得更好。但是现在...我们等待。如果您想要一种良好的高尔夫语言,请参阅“认真回答”,其中包含一些疯狂的内容。
艾迪生·克伦普

27

认真地,1个字节

N

如果堆栈为空(在开始时为空),则N推送歌词。然后将它们隐式打印在EOF上。

感谢@Mego修复了严重的解释器。


22
马丁在“ Hello World”挑战赛中说,请不要用无足轻重的语言打败无聊(但有效)的答案-这些问题对于此问题仍然很有用,因为它会尝试尽可能完整地编制目录。但是,主要是用作者实际上不得不努力打通代码的语言来提高答案的准确性。” 这个答案没有意思,但这是有效且最短的解决方案。
lirtosiast

1
在阅读问题时,我迫不及待想看到您发布了认真的答案。但看起来我什至不必等待。:)
Hexaholic

8
Seriusly ????????
Vajura 2015年

1
我期待看到您的解决方案而无需使用N:)
Mego

1
是的-我有4票赞成票,我的回答是有效的。我同意这里的最高评论中所说的内容。
艾迪生·克伦普

19

的JavaScript ES6,230个 218 198 196 192 188 185字节

for(x=99,z=(a=' on the wall')=>`${x||99} bottle${1-x?'s':''} of beer`+a;x;)alert(z()+', '+z`.
`+(--x?'Take one down and pass it around, ':'Go to the store and buy some more, ')+z()+'.')

只是修剪一些字节,同时仍保持其干净整洁且易于理解。

3个最新修订:

for(x=99,z=a=>`${x||99} bottle${1-x?'s':''} of beer${a||' on the wall'}`;x;)alert(z()+', '+z(`.
`)+(--x?'Take one down and pass it around, ':'Go to the store and buy some more, ')+z()+'.')

for(x=99,z=a=>(x||99)+' bottle'+(1-x?'s':'')+' of beer',w=' on the wall';x;)alert(z()+w+', '+z()+(--x?`.
Take one down and pass it around, `:`.
Go to the store and buy some more, `)+z()+w+'.')

for(x=99,o=' bottle',q=b=o+'s',e=' of beer',w=e+" on the wall";x;)alert(x+b+w+', '+x+b+e+(--x?`.
Take one down and pass it around, `+x:`.
Go to the store and buy some more, 99`)+(b=1-x?q:o)+w+'.')

1
通过将变量置于循环控件之外可以节省2个字节:x=99;w=" on the wall";e=" of beer";o=" bottle";b=o+"s";for(z="Go to the store and buy some more, "+x+b;0<x;)console.log(x+(2>x?o:b)+e+w+", "+x+(2>x?o:b)+e+".\n"+(1>--x?z:"Take one down and pass it around, "+x+(2>x?o:b))+e+w+".")
通用用户

这不是在代码中保存这两个字节的原因。实际上是删除了(--x <1)周围的括号。现在,出于可读性考虑,我会将变量保留在for语句中,以使它们保持在一起。
亚当·达利

1
@Stefnotch如果您想知道,我通过检查我的函数调用找到了此编辑...但是我不认为这是您的意图。不过,您的建议仍然是最后的选择。
亚当·达利2015年

1
@PaŭloEbermann它确实为每节经文执行警报,但是您可以随意将其更改为console.log以在控制台中执行,这将使它成为194个字节。再加上一次警告整个歌词在Firefox中是行不通的,至少...它精简了5到10句不错的经文。
亚当·达利

1
@Stefnotch。那么1-x目前被证明是有用的。
亚当·达利

18

的JavaScript ES6,328个 318 307 305字节

是一个匿名函数。f=在开头添加make函数并f()执行。

x=>eval('s=o=>v=(o?o:" no more")+" bottle"+(1==o?"":"s");for(o="",i=99;i>0;)o+=`${s(i)}@ on the wall, ${v}@.\nTake one down, pass it around, ${s(--i)}@ on the wall.\n`;o+`No more bottles@ on the wall, no more bottles@.\nGo to the store and buy some more, 99 bottles@ on the wall.`'.replace(/@/g," of beer"))

2
如果不仅仅是一个长字符串串联
那么

9
为什么从另一个站点复制随机ASCII艺术作品?
feersum

7
特别是由于它不起作用,它会发出警报:,+No, on the wall,,. Go to the store and buy some more, 99 bottles of beer on the wall.
普通用户

14

C,197196字节

main(i){for(i=299;i--/3;printf("%d bottle%s of beer%s%s",i/3?:99,"s"+5/i%2,i%3?" on the wall":i^3?".\nTake one down and pass it around":".\nGo to the store and buy some more",~i%3?", ":".\n\n"));}

我认为我已经达到了这种方法的极限。


1
"%d bottles of beer on the wallTake one down and pass it aroundGo to the store and buy some more,.\n"main(){for(;;)printf();}单独的字节是126个字节,因此这代表了一个硬的下限,除非有人找到一种方法来压缩或重用部分字符串,而不会产生大量开销。我怀疑您可能已经达到一般方法的极限,正负两个字节。

12

Java的304 301 300 295个字节

第一次发布答案。我听说我们可以使用枚举,但找不到方法。

interface A{static void main(String[]a){String b=" of beer",c=" on the wall",n=".\n",s;for(int i=100;i-->1;s=" bottle"+(i>1?"s":""),System.out.println(i+s+b+c+", "+i+s+b+n+(i<2?"Go to the store and buy some more, 99":"Take one down and pass it around, "+(i-1))+" bottle"+(i!=2?"s":"")+b+c+n));}}

不打高尔夫球

interface A {
    static void main(String[] a) {
        String b = " of beer", c = " on the wall", n = ".\n", s;
        for (int i = 100; i-- > 1; s = " bottle" + (i > 1 ? "s" : ""), System.out.println(i + s + b + c + ", " + i + s + b + n + (i < 2 ? "Go to the store and buy some more, 99" : "Take one down and pass it around, " + (i - 1)) + " bottle" + (i != 2 ? "s" : "") + b + c + n));
    }
}

感谢quartataJ AtkinBenjamin Urquhart


您可以通过使用节省2个字节i<2的地方i==1i>2这里:i!=2
J Atkin

@JAtkin谢谢。对于第一个,一切正常,输出保持不变。但对于第二个,如果我做出改变,最后一行将打印99 bottle,而不是99 bottles
亚辛Hajaj

1
事实证明,这对Java很好,但是对于Groovy(213 vs 245字节)来说,效果不好。
J Atkin

1
并非完全如此,groovy是JVM语言之一。大多数应用程序的Groovy代码比做相同事情的Java代码短。goovy-lang.org
J Atkin

1
@BenjaminUrquhart太好了!修改了!
Yassin Hajaj

11

认为有害的模板,667字节

Ap<Fun<Ap<Fun<Cat<Cat<Cat<Cat<Ap<A<1,1>,A<1>>,A<2,1>>,St<44,32>>,Ap<A<1,1>,A<1>>>,If<A<1>,Cat<Cat<Cat<Cat<St<46,10,84,97,107,101,32,111,110,101,32,100,111,119,110,32,97,110,100,32,112,97,115,115,32,105,116,32,97,114,111,117,110,100,44,32>,Ap<A<1,1>,Sub<A<1>,T>>>,A<2,1>>,St<46,10,10>>,Ap<A<0>,Sub<A<1>,T>>>,Cat<Cat<Cat<St<46,10,71,111,32,116,111,32,116,104,101,32,115,116,111,114,101,32,97,110,100,32,98,117,121,32,115,111,109,101,32,109,111,114,101,44,32>,Ap<A<1,1>,I<98>>>,A<2,1>>,St<46>>>>>,I<98>>>,Fun<Cat<Cat<Cat<Add<A<1>,T>,St<32,98,111,116,116,108,101>>,If<A<1>,St<'s'>,St<>>>,St<32,111,102,32,98,101,101,114>>>,St<32,111,110,32,116,104,101,32,119,97,108,108>>

扩展类别:

Ap<
    Fun<
        Ap<
            Fun<
                Cat<
                    Cat<Cat<Cat< Ap<A<1,1>,A<1>> , A<2,1> >, St<44,32> >, Ap<A<1,1>,A<1>> >,
                    If<A<1>,
                        Cat<Cat<Cat<Cat< St<46,10,84,97,107,101,32,111,110,101,32,100,111,119,110,32,97,110,100,32,112,97,115,115,32,105,116,32,97,114,111,117,110,100,44,32> , Ap<A<1,1>,Sub<A<1>,T>> >, A<2,1> >, St<46,10,10> >, Ap<A<0>,Sub<A<1>,T>> >,
                        Cat<Cat<Cat< St<46,10,71,111,32,116,111,32,116,104,101,32,115,116,111,114,101,32,97,110,100,32,98,117,121,32,115,111,109,101,32,109,111,114,101,44,32> , Ap<A<1,1>,I<98>> >, A<2,1> >, St<46> >
                    >
                >
            >,
            I<98>
        >
    >,
    Fun< Cat<Cat<Cat< Add<A<1>,T> , St<32,98,111,116,116,108,101> >, If<A<1>,St<'s'>,St<>>  >, St<32,111,102,32,98,101,101,114> > >,
    St<32,111,110,32,116,104,101,32,119,97,108,108>
>

11

哈斯克尔,228个 223字节

o=" of beer on the wall"
a n=shows n" bottle"++['s'|n>1]
b 1="Go to the store and buy some more, "++a 99
b n="Take one down and pass it around, "++a(n-1)
f=[99,98..1]>>= \n->[a n,o,", ",a n," of beer.\n",b n,o,".\n\n"]>>=id

函数f返回带有歌词的字符串。


10

///,341字节

/-/\/\///+/ bottle-)/\/&\/<\/
-(/\/\/?\/ ->/+s of beer-^/> on the wall-!/^,-$/>.
-@/$Take one down and pass it around,-#/^.
-*/?1@?0#<0!?0@-%/99!?9@?8#<8!?8@?7#<7!?7@?6#<6!?6@?5#<5!?5@?4#<4!?4@?3#<3!?3@?2#<2!?2@?1#<1!-&/?9#
%*-</
9(9/%*/</
8(8)7(7)6(6)5(5)4(4)3(3)2(2)1(1)0(0-
0/
- 0/ /#/1+s/1+/
% 01$Go to the store and buy some more, 099^.

编写此代码的正确说明将需要99年。

我可能只包括每个阶段的结果...

基本上,这会反复压缩歌词(就像///中的每个答案一样)。

在线尝试!

减压的每一步

由于替换后跟替换将具有字符串//,因此它将经常出现。

似乎经常出现,我决定压缩//-

对其进行解压缩后,结果如下:

/+/ bottle//)/\/&\/<\/
//(/\/\/?\/ //>/+s of beer//^/> on the wall//!/^,//$/>.
//@/$Take one down and pass it around,//#/^.
//*/?1@?0#<0!?0@//%/99!?9@?8#<8!?8@?7#<7!?7@?6#<6!?6@?5#<5!?5@?4#<4!?4@?3#<3!?3@?2#<2!?2@?1#<1!//&/?9#
%*//</
9(9/%*/</
8(8)7(7)6(6)5(5)4(4)3(3)2(2)1(1)0(0//
0/
// 0/ /#/1+s/1+/
% 01$Go to the store and buy some more, 099^.

该字符串 bottle仅出现了3次,但+无论如何我都将其压缩了:

/)/\/&\/<\/
//(/\/\/?\/ //>/ bottles of beer//^/> on the wall//!/^,//$/>.
//@/$Take one down and pass it around,//#/^.
//*/?1@?0#<0!?0@//%/99!?9@?8#<8!?8@?7#<7!?7@?6#<6!?6@?5#<5!?5@?4#<4!?4@?3#<3!?3@?2#<2!?2@?1#<1!//&/?9#
%*//</
9(9/%*/</
8(8)7(7)6(6)5(5)4(4)3(3)2(2)1(1)0(0//
0/
// 0/ /#/1 bottles/1 bottle/
% 01$Go to the store and buy some more, 099^.

然后,)对应于,/&/</后跟一个换行符,并(对应于//?/ ,这是以后会经常使用的模式:

/>/ bottles of beer//^/> on the wall//!/^,//$/>.
//@/$Take one down and pass it around,//#/^.
//*/?1@?0#<0!?0@//%/99!?9@?8#<8!?8@?7#<7!?7@?6#<6!?6@?5#<5!?5@?4#<4!?4@?3#<3!?3@?2#<2!?2@?1#<1!//&/?9#
%*//</
9//?/ 9/%*/</
8//?/ 8/&/</
7//?/ 7/&/</
6//?/ 6/&/</
5//?/ 5/&/</
4//?/ 4/&/</
3//?/ 3/&/</
2//?/ 2/&/</
1//?/ 1/&/</
0//?/ 0//
0/
// 0/ /#/1 bottles/1 bottle/
% 01$Go to the store and buy some more, 099^.

现在,我们将解压缩一些有用的字符串:

  • > 解压缩到 bottles of beer
  • ^ 解压缩到 bottles of beer on the wall
  • !解压缩为^,^上面是。
  • $解压缩为>.\n,这>是第一个规则,\n是换行符。
  • @解压缩为,$后跟Take one down and pass it around,,这$是上面的规则。

解压缩的代码现在变为:

/*/?1 bottles of beer.
Take one down and pass it around,?0 bottles of beer on the wall.
<0 bottles of beer on the wall,?0 bottles of beer.
Take one down and pass it around,//%/99 bottles of beer on the wall,?9 bottles of beer.
Take one down and pass it around,?8 bottles of beer on the wall.
<8 bottles of beer on the wall,?8 bottles of beer.
Take one down and pass it around,?7 bottles of beer on the wall.
<7 bottles of beer on the wall,?7 bottles of beer.
Take one down and pass it around,?6 bottles of beer on the wall.
<6 bottles of beer on the wall,?6 bottles of beer.
Take one down and pass it around,?5 bottles of beer on the wall.
<5 bottles of beer on the wall,?5 bottles of beer.
Take one down and pass it around,?4 bottles of beer on the wall.
<4 bottles of beer on the wall,?4 bottles of beer.
Take one down and pass it around,?3 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 bottles of beer on the wall.
<1 bottles of beer on the wall,//&/?9 bottles of beer on the wall.

%*//</
9//?/ 9/%*/</
8//?/ 8/&/</
7//?/ 7/&/</
6//?/ 6/&/</
5//?/ 5/&/</
4//?/ 4/&/</
3//?/ 3/&/</
2//?/ 2/&/</
1//?/ 1/&/</
0//?/ 0//
0/
// 0/ / bottles of beer on the wall.
/1 bottles/1 bottle/
% 01 bottles of beer.
Go to the store and buy some more, 099 bottles of beer on the wall.

9

Vim,139个字节

由于xsot保存了6个字节

i, 99 bottles of beer on the wall.<ESC>YIGo to t<SO> store and buy some more<ESC>qa
3P2xgJX$12.+<CAN>YITake one down a<SO> pass it around<ESC>o<ESC>q98@adk?s
xn.n.ZZ

这是我第一次尝试打高尔夫球Vim命令,尽管显然它很受欢迎ZZ由于字节数似乎已被接受,因此我将最终值包括在字节数中(写入文件并退出)。

旁注:任务已完成


说明

Command                                    Effect
-------------------------------------------------------------------------------------------
i, 99 bottles of beer on the wall.<ESC>    insert text at cursor
Y                                          copy this line into buffer
IGo to t<SO> store and buy some more<ESC>  insert text at beginning of line
                                           auto-complete "the" (<Ctrl-N>, searches forward)
qa                                         begin recording macro into "a"
<LF>                                       move down one line (if present)
3P                                         paste 3 times before cursor
2x                                         delete 2 characters at cursor
gJ                                         join this line with next (without space between)
X                                          delete character before cursor
$                                          move to last non-whitespace character of line
12.                                        repeat the last edit command (X) 12 times
+                                          move to column 0 of next line
<CAN>                                      numeric decrement (<Ctrl-X>)
Y                                          copy this line into buffer
ITake one down a<SO> pass it around<ESC>   insert text at beginning of line
                                           auto-complete "and" (<Ctrl-N>, searches forward)
o<ESC>                                     insert text on new line
q                                          stop recording macro
98@a                                       repeat macro "a" 98 times
dk                                         delete upwards (this line and the one above it)
?s<LF>                                     move to previous /s/
x                                          delete character at cursor
n.n.                                       repeat last match and delete 2 times
ZZ                                         write to file and exit

1
i99 bottles of beer on the wall.<ESC>Yqa3P$r,J5wDr.+<CAN>YITake one down and pass it around, <ESC>o<ESCjq98@aiGo to the store and buy some more, <ESC>kdk?s<LF>xnxnxZZ
稍有

@ xsot对此表示感谢。不知何故,我完全忽略/?
primo

顺便说一句,通过这种改进,有可能在anagol上达到153
xsot

@xsot知道了;)
primo

8

JavaScript的ES6,237 217 208 203 195个193 189 186字节

打高尔夫球变得越来越难...
编辑1:有人完全让我失望,如果我想获得最好的Javascript答案,看来我必须加倍努力。
编辑2:老实说,我不敢相信自己能打那么多高尔夫!

for(i=99,Y=" on the wall",o=k=>k+(i||99)+` bottle${i==1?'':'s'} of beer`;i;)alert(o``+Y+o`, `+o(--i?`.
Take one down and pass it around, `:`.
Go to the store and buy some more, `)+Y+`.`)

我在某个地方搞砸了吗?我也很抱歉使用alert,如果您想测试我的代码,请将其替换为console.log

当前,还有另一个值得注意的Javascript答案:“ 99瓶啤酒”。看看这个!:D


我会重新检查您的条件,您应该可以删节几个字节。尽力保持同步!
亚当·达利2015年

@AdamDally好!!:D但是我不喜欢复制别人的东西...(如果我只是复制您的代码,我会感到内......尽管如果我发现了一些改进,那是“可以接受的”):D
Stefnotch

@AdamDally是的,我弄乱了我的函数,节省了很多字节!(划线的线越来越长。。)
Stefnotch 2015年

优秀的!除非有其他选择,否则我会完全忽略,我觉得我们都快要走到了尽头。
亚当·达利

7

的JavaScript ES6,210个 209 205 199 198 196字节

s=""
for(i=299;--i>1;s+=`${i/3|0||99} bottle${5/i^1?"s":""} of beer`+(i%3?" on the wall":i^3?`.
Take one down and pass it around`:`.
Go to the store and buy some more`)+(~i%3?", ":`.

`));alert(s)

这是我的C提交的粗略翻译。我实际上并不了解JavaScript,因此肯定还有改进的空间。

编辑:整洁,我发现反引号


您可以用代替console.logalert而可以使用`代替“。然后可以用换行符替换\ n。(勾号用于模板字符串,这些字符串可以有换行符...)另外,恭喜您击败我!
Stefnotch

1
我认为除非有其他人比我console.log更容易测试,否则我将不理会输出。无论如何,感谢您使我陷入反感!
xsot

哇,超出您的范围!另外,感谢您使用|| 在您的代码中,它肯定派上了用场...(嗯,您可以更改console.log,而我的胜利将减少
为零。.XD

1
事实证明,跟上您的挑战!las,看到您的代码细分很有趣。
亚当·达利

1
@AdamDally基本上,每个节被分成3份具有以下结构:%d bottle%s of beer%s%s。计算每个经文的索引(瓶数)i/3|0时,每个子串的索引为i%3
xsot

7

Brainfuck,743字节

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

在线尝试!

上面在一些地方使用包装单元来保存指令。我还在755指令中制作了非包装版本。


未压缩

以下是Brainfuck注释语言的多语言

; byte sequence
; \n _ _ _ _ c \n comma space d t o l T G
++++++++++>>
--->++++>------>-->>++>+>>+>->++
[[>+++++++[>++>+>+<<<-]<-]+<+++]
>>>>>-->>-->>++>->+++[<]

c = 0
n = 100

>
while(n)
[
  n = n minus 1
  -<<
  N = str(n)
  ; first time \n _ becomes 9 9
  +[<->-----]<---[<[<]>[->]<]
  +<[>-]>[-<++++++++++<->>>]
  -[<->-----]<+++[<[<]>[+>]<]

  <->>>
  if(c)
  [
    >
    if(n)
    [
      'Take one down and'
      [>]<<<<.<<<<---.>>>-.<<<++++.<.>>>.-.<<.<.>-.>>+.<+++.>-.<<<.>---.>>.<<+++.
      ' pass it around' comma space
      <.>>>++.<<---.>----..<<.>>>>--.+++<<+.<<.>.>--.>-.<+++.->-.+<<+++.<<.>.<<<<-<
    ]>
    else
    [
      'Go to the store and'
      [>]<<<-.<<<.<<<.>>.>.<<<.>>.<++++.---.<.>>-.+.>.<--.<.<.>----.>>-.<<+++.
      ' buy some more' comma space
      <.>--.>+++.++++.<<.>>------.>+.--.<<+++.<.>>>.++.<-.++<.-<<.>.<<<<-
      N = '9'
      N
      <<<+++++++++.>>>
    ]
    <+>
  ]

  c = c plus 2
  <++

  while(c)
  [
    N
    <<[<]>[.>]>>>
    ' bottle'
    >>>.>--.>>.<..->>.<<<+++.<<<<
    if(n minus 1) 's'
    -[>>>>>.[<]]<[>]>+
    ' of beer'
    >>>.>>>.<<+.<.>----.+++..->-.++

    [<<]<-
    if(c minus 1)
    [
      ' on the wall'
      >>>>>.>>>.-.+<<<.>>.<++++.---.<.>>+++.---<----.+++>>>..[<<]
    ]

    <<[>]>-
    if(c minus 2)
    [
      period newline
      >>>>++.--<.<<<+
      if(c minus 1) newline
      [>>>.<<<<]>[>]<-<
    ]>>
    else
    [
      comma space
      >>.>.<<<<
    ]

    if(not n) c = c minus 2
    >[<<++>]

    c = c minus 1
    <[>]<-
  ]

  c = 1
  >+>
]

6

Python 2,204字节

n=198
while n:s="bottle%s of beer"%"s"[:n^2>1];print n%2*"GToa kteo  otnhee  dsotwonr ea nadn dp absusy  isto maer omuonrde,,  "[n>1::2]+`n/2or 99`,s,"on the wall"+[", %d %s."%(n/2,s),".\n"[:n]][n%2];n-=1

规范在空格方面的规格还不够完善,因此在此我假设最后一行需要有一个尾随换行符。如果规范另有说明,我将更新此答案。

我对此感到非常满意,但是看着无政府状态的高尔夫,我觉得这仍然可以打高尔夫,也许可以采用其他方法。


6

迷宫1195 1190 932字节

"{"9"
^ }
 ""
 <
 713.101.801..:611.111.89.23}!:({.23.44.001.011.711.111.411.79.23.611.501.23..:511.79.211.23.001.011.79.23.011.911.111.001.23.101.(.:111.23.101.701.79.48\.411..:101.89.23.201.111.23.511.101.801..:611.111.89.23}!:{.23.44..:801.79.911.23.101.401.611.23.(.:111.23.411..:101.89.23.201.111.23.511.101.801..:611.111.89.23}!:{
 _
 3`<
 _ ( 
""""
"
{(32.111.102.32.98.101:..114.32.111:.(.32.116.104.101.32.119.97.108:..46.\\49.32.98.111.116:..108.101.32.111.102.32.98.101:..114.32.111:.(.32.116.104.101.32.119.97.108:..44.32.49.32.98.111.116:..108.101.32.111.102.32.98.101:..114.46.\71.111.32.116.111.32.116.104.101.32.115:.).111.114.101.32.97.110.100.32.98.117.121.32.115.111.109.101.32.109.111.114.101.44.32.9!9!32.98.111.116:..108.101.115.32.111.102.32.98.101:..114.32.111:.(.32.116.104.101.32.119.97.108:..46.@
 )
 }
 <
 87\\.64..:801.79.911.23.101.401.611.23.(.:111.23.411..:101.89.23.201.111.23.511
 _
 3`<
 _ ( 
v"""

这有点过分了...

虽然迷宫不是特别擅长打印字符串(因为您需要按所有字符代码),但我认为应该可以通过使用更多但更短的长行并随着网格旋转变得更加疯狂来做得更好。

由于我认为对高尔夫的任何改进都会大大改变此代码的结构,因此我将等待解释,直到我对如何进一步打高尔夫球没有任何想法。


6

蟒蛇2,195

i=198
while i:s=`i/2or 99`+' bottle%s of beer'%'s'[1<i<4:];print['%s, '+s+'.','Take one down and pass it around, %s.\n',"Go to the store and buy some more, %s."][i%2+1/i]%(s+' on the wall');i-=1

i/2Sp3000的答案中得出了这个想法。


6

Windows Batch,376个字节

很长很丑:

@echo off
setlocal enabledelayedexpansion
set B=bottles
set C=on the wall
set D=of beer
for /l %%* in (99,-1,1) do (
set A=%%*
if !A! EQU 1 set B=bottle
echo !A! !B! !D! !C!, !A! !B! !D!.
set /a A=!A!-1
if !A! EQU 1 set B=bottle
if !A! EQU 0 (
echo Go to the store and buy some more, 99 bottles !D! !C!.
) else (
echo Take one down and pass it around, !A! !B! !D! !C!.
echo.
))

5

Python,254个字节

b,o,s,t="bottles of beer","on the wall","bottle of beer",".\nTake one down and pass it around,"
i=99;exec'print i,b,o+",",i,b+t,i-1,b,o+".\\n";i-=1;'*97
print"2",b,o+", 2",b+t+" 1",s,o+".\n\n1",s,o+", 1",s+".\nGo to the store, buy some more, 99",b,o+"."

非常简单,分配一些最常见的短语,将99到3的每一位打印出来,然后通过将变量和一些字符串加在一起打印最后几行。


5

朱莉娅227个 215 213字节

w=" on the wall"
b=" bottles"
o=" of beer"
k=b*o
for n=99:-1:1
println("$n$k$w, $n$k.
$(n>1?"Take one down and pass it around":"Go to the store and buy some more"), $(n>1?"$(n-1)$(k=b*"\b"^(n<3)*o)":"99$b"o)$w.
")end

这使用字符串插值("$variable")和三进制来构造输出并将其打印到STDOUT。

感谢Glen O,节省了14个字节!


1
而不是(n>1?" bottles":" bottle")" of beer"使用" bottle""s"^(n>1)*" of beer"-请注意,*之后是必需的,(n<1)因为否则它会尝试(n>1)" of beer"用作电源。另外,使用while n>0over 是否有任何好处for n=99:-1:1(它可以使结尾的条件更简单,并且避免了对的单独需求n=99)?
Glen O

也可以使用实际的换行符代替,\n并将中间部分切换为插值(而不是",n>1?...","使用$(n>1?..."))来保存字符,并将, 条件内部移动到下一部分之前,因此只需编写一次即可。
Glen O

实际上,请考虑一会儿结束的建议-我只是意识到,在做每节经文的最后一个数字时,您必须减去一个,因此没有净收益。
Glen O

@GlenO一如既往地感谢您的宝贵建议!
Alex A.

1
我希望能够提出一个建议-有点傻,如果您有足够的代表在未经原始答复者接受的情况下进行编辑,则不允许该选项。如果确实以任何方式踩到脚趾,我对此表示歉意。我只是将对“一瓶啤酒”部分的评估移到了最后,因此只需要执行一次,然后将其初始化即可。我还使用了退格键而不是条件“ s”来节省一些时间。
Glen O

5

JavaScript ES6,214个字节

编辑:删除所有先前的代码,如果您想查看旧的代码,请查看编辑。

弹出窗口有限:

p='.';o=" of beer";e=o+" on the wall";i=99;u=m=>i+" bottle"+(i==1?'':'s');while(i>0){alert(u()+e+", "+u()+o+p+(--i>0?"Take one down and pass it around, "+u()+e:"Go to the store and buy some more, 99 bottles"+e)+p)}

展开:

p='.';
o=" of beer";
e=o+" on the wall";
i=99;
u=m=>i+" bottle"+(i==1?'':'s');
while(i>0){
    alert(u()+e+", "+u()+o+p+(--i>0?"Take one down and pass it around, "+u()+e:"Go to the store and buy some more, 99 bottles"+e)+p)
}

@commenters:感谢您使用箭头功能,节省了15个字节

对于无限量啤酒,只需在此处使用此代码,即212个字节

p='.';o=" of beer";e=o+" on the wall";i=99;u=m=>i+" bottle"+(i==1?'':'s');while(i>0){alert(u()+e+", "+u()+o+p+(--i>0?"Take one down and pass it around, "+u()+e:"Go to the store and buy some more, "+u(i=99)+e)+p)}

1
我无法运行代码,您使用的是什么浏览器/环境?“ SyntaxError:缺少;在声明之前”另外,请查看箭头功能!
Stefnotch

我花了点时间找到语法错​​误+o',然后将其更改为+o+'。还看到了改变循环和答案的机会。将现在检查出箭头功能:)
扎曼

1
最后一个解决方案的232字节:b=a=>a+" bottle"+(1<a?"s":"");for(i=100;100>--i;)l="\n",p="."+l,o=" of beer",e=o+" on the wall",alert(l+b(i)+e+", "+b(i)+o+p+(1<i?"Take one down and pass it around, "+b(i-1)+e:"Go to the store and buy some more, "+b((i=100)-1)+e)+p)
通用用户

经过一番摸索之后,我坚持了while下来,现在马上发布结果代码。感谢您的代码审查!:)
扎曼

5

CJam,149个 148 146 144 138 137 134字节

00000000: 39 39 7b 5b 22 2c 2e 22 22 01 bd 8f 2d b4 49 b5 f5  99{[",.""...-.I..
00000011: 9d bd 21 e8 f2 72 27 df 4d 4f 22 7b 32 36 39 62 32  ..!..r'.MO"{269b2
00000022: 35 62 27 61 66 2b 27 6a 53 65 72 28 65 75 5c 2b 2a  5b'af+'jSer(eu\+*
00000033: 7d 3a 44 7e 4e 4e 32 24 32 3e 29 34 24 4a 3c 5c 4e  }:D~NN2$2>)4$J<\N
00000044: 5d 73 27 78 2f 39 39 40 2d 73 2a 7d 2f 27 73 2d 5d  ]s'x/99@-s*}/'s-]
00000055: 22 07 9c 4b a2 4e 15 d7 df d5 82 88 c9 d9 a7 ad 37  "..K.N..........7
00000066: 16 7e 76 22 44 33 35 2f 28 5d 22 41 90 1d b1 f3 69  .~v"D35/(]"A....i
00000077: ba 3d 05 45 81 50 af 07 e4 1b 38 f7 19 22 44        .=.E.P....8.."D

上面的hexdump可以用反转xxd -r。在CJam解释器中在线尝试。

以9个额外的字节为代价,总共143个字节,我们可以避免不可打印的字符:

99{[", X bottles of beer on the wall."NN2$2>)4$J<\N]s'X/99@-s*}/'s-]"Take one down and pass it around"*35/("Go to the store and buy some more"\

这个怎么运作

99{         e# For each I in [0 ... 98]:
  [         e# 
    ",."    e#     Push that string.
    "…"     e#     Push a string.
    {       e#     Define a decoder function:
      269b  e#       Convert the string from base 269 to integer.
      25b   e#       Convert from integer to base 25.
      'af+  e#       Add 'a' to each base-25 digit.
      'jSer e#       Replace j's with spaces.
      (     e#       Shift the first character from the resulting string.
      eu    e#       Convert it to uppercase.
      \+    e#       Prepend it to the remaining string.
      *     e#       Join the string/array on the stack, using the 
            e#       generated string as delimiter.
    }:D~    e#     Name the function D and execute it.
            e#     This pushes ", x bottles of beer on the wall.".
    NN      e#     Push two linefeeds.
    2$      e#     Push a copy of the generated string.
    2>)     e#     Discard the first two characters and pop the dot.
    4$      e#     Push another copy of the generated string.
    J<      e#     Discard all but the first 19 characters.
            e#     This pushes ", x bottles of beer on the wall".
    \N      e#     Swap the string with the dot and push a linefeed.
  ]s        e#   Collect in an array and cast to string.
  'x/       e#   Split at occurrences of 'x'.
  99@-      e#   Rotate I on top of 99 and compute their difference.
  s*        e#   Cast to string and and join.
            e#   This replaces x's with 99-I.
}/          e#
's-         e# Remove all occurrences of 's' for the last generated string.
]           e# Wrap the entire stack in an array.
"…"D        e# Join the array with separator "Take one down and pass it around".
35/(        e# Split into chunks of length 35 and shift out the first.
            e# This shifts out ", 99 bottles of beer on the wall.\n\n".
]           e# Wrap the modified array and shifted out chunk in an array.
"…"D        e# Join the array with separator "Go to the store and buy some more".

基地259?有趣。
lirtosiast

Base 256有回车符,不能与在线解释器一起使用。幸运的是,基数259不会产生超出ISO 8559-1范围的字符。
丹尼斯

我以为CJam比GolfScript短至少2个字节-几乎是微不足道的。没想到137!
2015年

1
@primo公平地说,大多数节省来自基本转换。可悲的是,使用base两次已经在GolfScript中添加了8个字节...
Dennis

5

C,303个 299 297字节

#define B"%d bottle%s of beer"    
#define O" on the wall"
#define P printf(
#define V(n,m,S)q(n);P O);P", ");q(n);P S);q(m);P".\n");
*s[]={"","s"};q(n){P B,n,s[n>1]);}main(){for(int i=99;--i;){V(i+1,i,".\nTake one down and pass it around, ")P"\n");}V(1,99,".\nGo to the store and buy some more, ");}

用编译gcc -std=c99 -w


1
高尔夫球压缩到300个字节:... for(int i = 99;-i;){V(i + 1,i,“ ....
Glenn Randers-Pehrson

@ GlennRanders-Pehrson谢谢。我还删除了main()之前的换行符。
firefrorefiddle 2015年

5

GolfScript,143个字节

[99.{[', '\.' bottle''s of beer'@(:i!>' on the wall''.
'n].1>~;5$4<\'Take one down and pass it around'i}**'Go to the store and buy some more'](

可能仍有改进的空间。我认为接近最终修订版。


3
刚刚将anagol GolfScript记录提高了12个字节。
2015年

5

Mathematica,238 226 222 224字节

感谢MartinBüttner,节省了几个字节。

a={ToString@#," bottle",If[#<2,"","s"]," of beer"}&;b=a@#<>" on the wall"&;Echo[{b@n,", ",a@n,".
"}<>If[n<2,"Go to the store and buy some more, "<>b@99<>".","Take one down and pass it around, "<>b[n-1]<>".
"]]~Do~{n,99,1,-1}

5

Brainfuck,4028字节

这太可怕了。重复很多,效率很低,因此不会获得任何奖励。但是,我启动了它,并决心完成它。

我可能会尝试改善它,但可能不会,因为坦率地说,我的大脑被搞砸了。

打高尔夫球

>>+++[-<+++<+++>>]>>++++++[-<++++++++++<++++++++++>>]<---<--->>>+++++[-<++++++>]
<++>>++++++++++[-<++++++++++>]<-->>++++++++++[-<+++++++++++>]<+>>++++++++++[-<++
++++++++>]<+>>++++++++++[-<++++++++++>]<++>>++++++++++[-<+++++++++++>]<++++++>>+
+++++++++[-<++++++++++>]<++++>>++++++++++[-<+++++++++++>]<-->>++++++++++[-<+++++
++++++>]<++++>>++++++++++[-<+++++++++++>]<+++++>>++++++++++[-<+++++++++++>]>++++
++++++[-<+++++++++++>]<+++++++++>>++++++++++[-<++++++++++>]<--->>+++++[-<++++++>
]<++>>++++[-<++++++++++++>]<---->>++++[-<++++++++++++>]<-->++++++++++>>+++++++++
+[-<+++++++++++>]<--->>++++++++++[-<++++++++++>]>++++++++++[-<+++++++++++>]<++>>
++++++++++[-<++++++++++>]<+++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>>>.<<<<<<<<<<<<<<<<<.>>>>>>>>>>.>>>>>>>.<<<<<<<<<
<<<<<<<<<.>>>>>>.<<<<<.>>>>>>>>>>>.<.<<<<<<<<<<<<<<..>.>.>.>>>..>>.<<<<.>>>>>>.<
<<<<<<<<.>>.>>.<<<<.>.>>..>>>>>.<<<<<<<<.>>.>>>>>>>>.>>>.<<<<<<<<.>.<<<.<<<.>>>>
>>>>>>>.>.<<<<<..>>>>>>>>.>.

不打高尔夫球

# SETUP COUNTERS
>>+++[-<+++<+++>>]
>>++++++[-<++++++++++<++++++++++>>]<---<--->>

# SETUP CONSTANTS
>+++++[-<++++++>]<++>
>++++++++++[-<++++++++++>]<-->        # B
>++++++++++[-<+++++++++++>]<+>        # O
>++++++++++[-<++++++++++>]<+>         # E
>++++++++++[-<++++++++++>]<++>        # F
>++++++++++[-<+++++++++++>]<++++++>   # T
>++++++++++[-<++++++++++>]<++++>      # H
>++++++++++[-<+++++++++++>]<-->       # L
>++++++++++[-<+++++++++++>]<++++>     # R
>++++++++++[-<+++++++++++>]<+++++>    # S
>++++++++++[-<+++++++++++>]           # N
>++++++++++[-<+++++++++++>]<+++++++++># W
>++++++++++[-<++++++++++>]<--->       # A
>+++++[-<++++++>]<++>                 # SPACE
>++++[-<++++++++++++>]<---->          # Comma
>++++[-<++++++++++++>]<-->            # Stop
++++++++++>                           # Newline
>++++++++++[-<+++++++++++>]<--->      # K
>++++++++++[-<++++++++++>]            # D
>++++++++++[-<+++++++++++>]<++>       # P
>++++++++++[-<++++++++++>]<+++++>     # I
>++++++++++[-<+++++++++++>]<+++++++   # U

# BACK TO START
<<<<<<<<<<<<<<<<<<<<<<<<<
[>
    [
        -> # Dec x0 counter
        .> # Print 0x char
        .> # Print x0 char
        .>
        .>.>>>..>>.<<<<.>>>>>>. # Bottles
        <<<<<<<<<.
        >>.>>.       # Of
        <<<<.
        >.>>..>>>>>. # Beer
        <<<<<<<<.
        >>.>>>>>>>>. # On
        >>>.
        <<<<<<<<.>.<<<. # The
        <<<.
        >>>>>>>>>>>.>.<<<<<.. # Wall
        >>>>>>>.     # Comma
        <.
        <<<<<<<<<<<<<<<.>.- # Counter with decrement
        >.
        >.>.>>>..>>.<<<<.>>>>>>. # Bottles
        <<<<<<<<<.
        >>.>>.       # Of
        <<<<.
        >.>>..>>>>>. # Beer
        >>>>>>>.     # Stop
        >.           # Newline
        <<<<<<<<<<<.>>>>>>>.>>>>>.<<<<<<<<<<<<<<. # Take
        <<<.
        >>.>>>>>>>>.<<<<<<<. # One
        <<<.
        >>>>>>>>>>>>>>>>>>.<<<<<<<<<<<<<<<<.>>>>>>>>>.<. # Down
        >>>. 
        <.<<.>>>>>>>>.  # And
        <<<<<.
        >>>>>>.<<<<<<<.<<<..    # Pass
        >>>>.
        >>>>>>>.<<<<<<<<<<<<<<<. # It
        >>>>>>>>.
        <.<<<<.<<<<<<.>>>>>>>>>>>>>>>>>>>.<<<<<<<<<<<.>>>>>>>>. # Around
        <<<<. # Comma
        <.
        <<<<<<<<<<<<<<<.>. # 0x and x0
        >.
        >.>.>>>..>>.<<<<.>>>>>>. # Bottles
        <<<<<<<<<.
        >>.>>.  # Of
        <<<<.
        >.>>..>>>>>. # Beer
        <<<<<<<<.
        >>.>>>>>>>>. # On
        >>>.
        <<<<<<<<.>.<<<. # The
        <<<.
        >>>>>>>>>>>.>.<<<<<.. # Wall
        >>>>>>>>.    # Stop
        >..   # Newline x2
        <<<<<<<<<<<<<<<<<<<      # Reset loop
    ]
    <-
    >+++++++++
    >.>.
    >.
    >.>.>>>..>>.<<<<.>>>>>>. # Bottles
    <<<<<<<<<.
    >>.>>.       # Of
    <<<<.
    >.>>..>>>>>. # Beer
    <<<<<<<<.
    >>.>>>>>>>>. # On
    >>>.
    <<<<<<<<.>.<<<. # The
    <<<.
    >>>>>>>>>>>.>.<<<<<.. # Wall
    >>>>>>>.     # Comma
    <.
    <<<<<<<<<<<<<<<.- # 0x with decrement
    >.+++++++++ # x0 with increment
    >.
    >.>.>>>..>>.<<<<.>>>>>>. # Bottles
    <<<<<<<<<.
    >>.>>.       # Of
    <<<<.
    >.>>..>>>>>. # Beer
    >>>>>>>.     # Stop
    >.           # Newline
    <<<<<<<<<<<.>>>>>>>.>>>>>.<<<<<<<<<<<<<<. # Take
    <<<.
    >>.>>>>>>>>.<<<<<<<. # One
    <<<.
    >>>>>>>>>>>>>>>>>>.<<<<<<<<<<<<<<<<.>>>>>>>>>.<. # Down
    >>>. 
    <.<<.>>>>>>>>.  # And
    <<<<<.
    >>>>>>.<<<<<<<.<<<..    # Pass
    >>>>.
    >>>>>>>.<<<<<<<<<<<<<<<. # It
    >>>>>>>>.
    <.<<<<.<<<<<<.>>>>>>>>>>>>>>>>>>>.<<<<<<<<<<<.>>>>>>>>. # Around
    <<<<. # Comma
    <.
    <<<<<<<<<<<<<<<.>. # Counter
    >.
    >.>.>>>..>>.<<<<.>>>>>>. # Bottles
    <<<<<<<<<.
    >>.>>.  # Of
    <<<<.
    >.>>..>>>>>. # Beer
    <<<<<<<<.
    >>.>>>>>>>>. # On
    >>>.
    <<<<<<<<.>.<<<. # The
    <<<.
    >>>>>>>>>>>.>.<<<<<.. # Wall
    >>>>>>>>.    # Stop
    >..   # Newline x2
    <<<<<<<<<<<<<<<<<<<<      # Reset outer loop
]
>-- # Decrement counter to only count from 7
# Last 8 loop
[
    -> # Dec counter
    >. # Print x0 char    
    >.
    >.>.>>>..>>.<<<<.>>>>>>. # Bottles
    <<<<<<<<<.
    >>.>>.       # Of
    <<<<.
    >.>>..>>>>>. # Beer
    <<<<<<<<.
    >>.>>>>>>>>. # On
    >>>.
    <<<<<<<<.>.<<<. # The
    <<<.
    >>>>>>>>>>>.>.<<<<<.. # Wall
    >>>>>>>.     # Comma
    <.
    <<<<<<<<<<<<<<.- # x with decrement
    >.
    >.>.>>>..>>.<<<<.>>>>>>. # Bottles
    <<<<<<<<<.
    >>.>>.       # Of
    <<<<.
    >.>>..>>>>>. # Beer
    >>>>>>>.     # Stop
    >.           # Newline
    <<<<<<<<<<<.>>>>>>>.>>>>>.<<<<<<<<<<<<<<. # Take
    <<<.
    >>.>>>>>>>>.<<<<<<<. # One
    <<<.
    >>>>>>>>>>>>>>>>>>.<<<<<<<<<<<<<<<<.>>>>>>>>>.<. # Down
    >>>. 
    <.<<.>>>>>>>>.  # And
    <<<<<.
    >>>>>>.<<<<<<<.<<<..    # Pass
    >>>>.
    >>>>>>>.<<<<<<<<<<<<<<<. # It
    >>>>>>>>.
    <.<<<<.<<<<<<.>>>>>>>>>>>>>>>>>>>.<<<<<<<<<<<.>>>>>>>>. # Around
    <<<<. # Comma
    <.
    <<<<<<<<<<<<<<. # Count
    >.
    >.>.>>>..>>.<<<<.>>>>>>. # Bottles
    <<<<<<<<<.
    >>.>>.  # Of
    <<<<.
    >.>>..>>>>>. # Beer
    <<<<<<<<.
    >>.>>>>>>>>. # On
    >>>.
    <<<<<<<<.>.<<<. # The
    <<<.
    >>>>>>>>>>>.>.<<<<<.. # Wall
    >>>>>>>>.    # Stop
    >..   # Newline x2
    <<<<<<<<<<<<<<<<<<<     # Reset loop
]
# Last but 1 exception
>>. # Counter
>.
>.>.>>>..>>.<<<<.>>>>>>. # Bottles
<<<<<<<<<.
>>.>>.       # Of
<<<<.
>.>>..>>>>>. # Beer
<<<<<<<<.
>>.>>>>>>>>. # On
>>>.
<<<<<<<<.>.<<<. # The
<<<.
>>>>>>>>>>>.>.<<<<<.. # Wall
>>>>>>>.     # Comma
<.
<<<<<<<<<<<<<<.- # x with decrement
>.
>.>.>>>..>>.<<<<.>>>>>>. # Bottles
<<<<<<<<<.
>>.>>.       # Of
<<<<.
>.>>..>>>>>. # Beer
>>>>>>>.     # Stop
>.           # Newline
<<<<<<<<<<<.>>>>>>>.>>>>>.<<<<<<<<<<<<<<. # Take
<<<.
>>.>>>>>>>>.<<<<<<<. # One
<<<.
>>>>>>>>>>>>>>>>>>.<<<<<<<<<<<<<<<<.>>>>>>>>>.<. # Down
>>>. 
<.<<.>>>>>>>>.  # And
<<<<<.
>>>>>>.<<<<<<<.<<<..    # Pass
>>>>.
>>>>>>>.<<<<<<<<<<<<<<<. # It
>>>>>>>>.
<.<<<<.<<<<<<.>>>>>>>>>>>>>>>>>>>.<<<<<<<<<<<.>>>>>>>>. # Around
<<<<. # Comma
<.
<<<<<<<<<<<<<<. # Count
>.
>.>.>>>..>>.<<<<. # Bottle
<<<.
>>.>>.  # Of
<<<<.
>.>>..>>>>>. # Beer
<<<<<<<<.
>>.>>>>>>>>. # On
>>>.
<<<<<<<<.>.<<<. # The
<<<.
>>>>>>>>>>>.>.<<<<<.. # Wall
>>>>>>>>.    # Stop
>..   # Newline x2
# Last 1 exception
<<<<<<<<<<<<<<<<<. # Counter
>.
>.>.>>>..>>.<<<<. # Bottle
<<<.
>>.>>.       # Of
<<<<.
>.>>..>>>>>. # Beer
<<<<<<<<.
>>.>>>>>>>>. # On
>>>.
<<<<<<<<.>.<<<. # The
<<<.
>>>>>>>>>>>.>.<<<<<.. # Wall
>>>>>>>.     # Comma
<.
<<<<<<<<<<<<<<.++++++++ # x with reset to 99
>.
>.>.>>>..>>.<<<<. # Bottle
<<<.
>>.>>.       # Of
<<<<.
>.>>..>>>>>. # Beer
>>>>>>>.     # Stop
>.           # Newline
>----        # Change K to G
>>+++++++++  # Change P to Y
>++++        # Change I to M
<<<.<<<<<<<<<<<<<<<. # Go
<<.
>>>>>.<<<.           # To
<<.
>>>>>.>.<<<.         # The
<<<.
>>>>>>>>>.<<<<.<<<.>>>>>>.<<<<<. # Store
<<<.
>>>>>>>>>>>>.<<.>>>>>>>>.       # And
<<<<<.
<<<<<<<<<<<<.>>>>>>>>>>>>>>>>>>>>.<<. # Buy
<<<<<<.
<<<<.<<<<<<<.>>>>>>>>>>>>>>>>>>.<<<<<<<<<<<<<<<<<. # Some
>>>>>>>>>>.
>>>>>>>.<<<<<<<<<<<<<<<<<<.>>>>>>.<<<<<. # More
>>>>>>>>>>>.
<.
<<<<<<<<<<<<<<..  # 99
>.
>.>.>>>..>>.<<<<.>>>>>>. # Bottles
<<<<<<<<<.
>>.>>.  # Of
<<<<.
>.>>..>>>>>. # Beer
<<<<<<<<.
>>.>>>>>>>>. # On
>>>.
<<<<<<<<.>.<<<. # The
<<<.
>>>>>>>>>>>.>.<<<<<.. # Wall
>>>>>>>>.    # Stop
>.   # Newline x2

输出:

在这里自己尝试!
好的,因此URL似乎太长而无法在此处包含,因此您需要复制/粘贴才能自己尝试。

我使用此解释器对其进行了测试。


4

PHP,251字节

这解决了复数/单数问题。

<?php for($i=99;$i>0;$i--){$b=" of beer";$s=" bottles$b";$r=" bottle$b";$w=" on the wall";$h=$i-1;echo$h>=1?"$i$s$w, $i$s.\nTake one down and pass it around, $h".($h<2?$r:$s)."$w.\n\n":"$i$r$w, $i$r. \nGo to the store and buy some more, 99$s$w.\n\n";}

可读性:

for ($i=99; $i > 0; $i--) {
  $b = " of beer";
  $s = " bottles$b";
  $r = " bottle$b";
  $w = " on the wall";
  $h = $i - 1;
  echo $h >= 1 ? "$i$s$w, $i$s.\nTake one down and pass it around, $h" . ($h<2 ? $r : $s) . "$w.\n\n" : "$i$r$w, $i$r. \nGo to the store and buy some more, 99$s$w. \n\n";
}



4

1141 1109字节

我仍然有很大的空间可以在所有空白处进一步打高尔夫球,但是它变得很难追随,而且很容易折断:)它与我为这个问题发布的内容非常相似,只不过它去了商店在啤酒达到1之前,用于参数的单元格已移动。我还对布局进行了很大的更改。一旦尝试了几种布局,我将尝试做一个解释。

P'P''''>`++++++)++'''P>`+++++++++++++)'''''''''''P+++++++++++++`P```>`++\ v@@++++++++++L(`<@+p'''''''''PL<
v``P''(++++++`<P'''''''''(++++++++`<L```P'+++++P'+++P'++++++P'++++P''''(/> p++@---@``p@'''''p+++@`> `)''' 'p-@''p\
>''p:'p@'p@'\>n'   >`>`)'''p@''''p@\>n'''p@''''p@-@````p@'''''p@`>`)'''''/v  `P+p``@p'''(`<@-p''''''''P'+up(`<`@@/
^/``@@p'@p''/ >'''\ /-p'@p'@p``@p``/`>-'P''''''''p+@>`)''p`n`L++++++++++@S 'p@````p@````p@'''''p@`p@````p@'''''p@```p++@---@``p@'''''p-@+@`p@+++@``p-@``p@'p-@'''p-@```p++@`p@'p@''''p+@++++@`````p@'''''p-@`p@--@``p-@``p@''''p--@p@+++@``p-@''''p-@>`)'''p@'p+:`p@'p@'''p@'p@@``p@`p-@'''p-@`>`)'''p@''''p@``p@``p@'p@'p-@@'''p--@`>`)'''p@''''p@-@````p@'''''p@`>`)'''''p++@---@``p@'''''p+++@`>`)''''p-@''p@@'''p+@H
^\p@`p-@```p`//'''/ \@@'''p--@`>`)'p/``````@pS@++++++++++L`<vP+p`P-p`P-p`@ p'''(`<@-p''''@--p``@-p`@+p'@p`@--p''''@-p'@p`````@p'''@+++p''@p```\
^             \'p-@/v               \ p-@''p-@`p-@``p@''''p@ -@``p-@``p@'p ++@'''p@'p+++@`p-@````p@'p-@'''p-@```p++@`p@''''p+@```p-@''''p-@@``/
^                   <                                       <             <

此处的堆栈片段中尝试


4

PHP,250 246 244 233 228字节

我相信这是迄今为止最小的。这是基于247镜头的图像,并进行了一些修改以进一步最小化。

最小化

<?php $b=99;function x($n){return"$n bottle".($n-1?'s':'')." of beer";}$y=" on the wall";while($b){$c=x($b);echo"$c$y, $c.\n",--$b?"Take one down and pass it around":"Go to the store and buy some more",", ".x($b?:99)."$y.\n\n";}

展开式

<?php

$b=99;
function x($n){return"$n bottle".($n-1?'s':'')." of beer";}
$y=" on the wall";
while(b){
    $c=x($b);
    echo"$c$y, $c.\n",--$b?"Take one down and pass it around":"Go to the store and buy some more",", ".x($b?:99)."$y.\n\n";
}

1
由于您可以从命令行运行php -r与之等效perl -e或相似的PHP ,因此可以省略开始标记。请参阅“ 使用-r代码而不是代码标签运行PHP”中的相关讨论。
manatwork

啊,谢谢@manatwork,我想我可以再把我弄下来。
Phroggyy 2015年

while($b)效果也一样。
frnhr

最后有一个额外的换行符。
frnhr

感谢您的整个建议!不过,换行符是必需的,以便在经文之间有一条线
Phroggyy 2015年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.