用您喜欢的编程语言唱生日快乐


119

您最喜欢的编程语言刚刚度过了生日。保持友善并唱生日快乐歌曲。

当然,您应该通过使用该语言编写程序来完成此任务。该程序不输入任何内容,并将以下文本写入标准输出或任意文件:

Happy Birthday to You
Happy Birthday to You
Happy Birthday Dear [your favourite programming language]
Happy Birthday to You

您应该替换方括号中的部分(并省略方括号)。

这是一场代码高尔夫-最短的代码胜出。

更新

我很高兴这个问题引起了极大的兴趣。让我添加一些有关得分的额外信息。如最初所述,这个问题是代码高尔夫球,因此最短的代码将获胜。优胜者将在本周末(10月19日)被选出。

但是,我也会用其他投票方式奖励其他机智的人(我也鼓励大家也这样做)。因此,尽管这是一场代码高尔夫比赛,但也欢迎不太简短的答案。

结果

祝贺Optimizer,他以42字节长的CJam 提交赢得了比赛。


2
我们是否可以将编程语言的名称算作一个字节,因为它对于使用JavaScript之类的冗长语言进行编码的人与在C语言中进行编码的人来说似乎才是公平的。我们真的在寻找最有创意的逻辑吗?
MonkeyZeus 2014年

14
为什么尽管对Bonbon歌曲的所有否决都为此赞誉?这同样是无聊的挑战。
xnor 2014年

10
我可能应该提到这首歌已受版权保护,发行这些程序可能会引起DMCA
棘手的问题2014年


4
至少其中一个答案打印领先换行符。可以吗
丹尼斯

Answers:


47

CJam,46 42个字节

"Happy Birthday to You
"___F<"Dear CJam
"@

这个怎么运作:

"Happy Birthday to You
"___                          "Push "Happy Birthday to You\n" string to stack 4 times";
    F<                        "From the last string, take only first 15 characters. F is a";
      "Dear CJam              "preinitialized variable whose value is 15";
"                             "Push "Dear CJam\n" to stack";
 @                            "Take the third string from end and put it to end";

在代码末尾,这使堆栈如下所示:

["Happy Birthday to You
" "Happy Birthday to You
" "Happy Birthday " "Dear CJam
" "Happy Birthday to You
"]

自动打印以输出为

Happy Birthday to You
Happy Birthday to You
Happy Birthday Dear CJam
Happy Birthday to You

在这里尝试(复制代码并运行)


1
“前15个字符”是F吗?那是怎么知道数字15的?
vijrox

1
是的,af是10-15。
雅各布

122

LOLCODE:109(具有“正确”拼写的105)

LOLCODE不是打高尔夫球的好语言,特别是因为您在缩短代码时会失去所有的美感和表现力。

HAI
H R "HAPPY BIRTHDAY "
T R SMOOSH H "TO YOU"
VISIBLE T
VISIBLE T
VISIBLE SMOOSH H "DEAR LOLCODE"
VISIBLE T

使用loljs进行测试

这是我的首选格式,重187个字符(为清楚起见添加了空格):

HAI
H R "HAPPY BERFDAY "
IM IN YR LOOP UPPIN YR N TIL BOTH SAEM N AN 4
  VISIBLE H!
  BOTH SAEM N AN 2, O RLY?
    YA RLY
      VISIBLE "DEER LOLCODE"
    NO WAI
      VISIBLE "2U"
    OIC
IM OUTTA YR LOOP
KTHXBAI

15
我只是知道会有LOLCODE答案。顺便说一句,您是否会在lwrcase中删除kwotez?KTHXBYE。
级圣河

2
我曾尝试编写LOLCODE答案以解决前一段时间的另一个挑战,但是对于代码打高尔夫来说太冗长了,而且它缺乏体面的数据结构和创建复杂功能的能力,因此相当有限!

3
这个答案给了我下载LOCODE并真正正确学习它的冲动。
法拉普2014年

2
这很棒!!
AStopher

89

Mathematica-条码生日祝福-字节过多

这会打印经文并大声朗读。

生日快乐

祝你
生日快乐祝你
生日快乐尊敬的Mathematica
祝你生日快乐

StringReplace用换行符替换每个逗号。条形码不能包含控制字符。


13
我在键盘上看不到条形码按钮!我该如何测试?
matsjoyce 2014年

17
我喜欢10条形码(右下角)中有一个,因为它BarcodeRecognize是在Mathematica 10中引入的。^^
Martin Ender 2014年

是! 我没有注意到。
DavidC 2014年

11
我实际上是用QR码阅读器扫描的。每个逗号后都有多余的空格,如果您无法保存字节,那么,哦,等等。没关系。
Timwi'1

55

TI基本(53字节)

好吧,由于每个人都在使用自己喜欢的编程语言,所以我不妨添加我以前喜欢的一种。多年来(在我毕业于实际的编程语言之前),我花了很多时间在比智能手机大一半的窗口中键入命令。

"HAPPY BIRTHDAY TO YOU
Disp Ans,Ans,sub(Ans,1,15)+"DEAR TI-BASIC
Ans

我的计算器不支持小写字母,并且只能是字符串的变量是Str1,Str2等。


TI-Basic的哪种口味?我对TI-84非常熟悉。
Jesan Fafon 2014年

7
看到TI基础知识总是很高兴。这似乎是标准的8x TI-Basic,其中任何表达式都自动存储到Ans,可以将其用作怪异且难以遵循的优化策略。我也开始使用这种很棒的语言进行编程。
密码破解者2014年

4
编者注:您可以在评论中发布任何更改(在这种情况下,损失8个字符),而不仅仅是编辑吗?那会让我觉得这仍然是我的答案。
2014年

2
+1!这也是我学会编程的方式。我为TI-83:D构建了Tron,但速度很慢,因此不好玩。
Nacht

2
哈哈,太棒了。我为TI-83制作了二十一点游戏。在此过程中,我非常了解二十一点的所有规则。
thomasrutter

44

Sed,60 55字节

(添加了1个字符,因为sed没有输入就无法工作。)

s/^/Happy Birthday To You/
h
G
G
G
s/To You/Dear sed/3

肯定不是赢家,张贴来展示其仅替换第n 事件sed的罕见s///功能。

bash-4.3$ sed 's/^/Happy Birthday To You/;h;G;G;G;s/To You/Dear sed/3' <<< ''
Happy Birthday To You
Happy Birthday To You
Happy Birthday Dear sed
Happy Birthday To You

Sed(简短但不有趣):52个字符

s/^/Happy Birthday To You/
h
G
p
s/To You/Dear sed/

样品运行:

bash-4.3$ sed 's/^/Happy Birthday To You/;h;G;p;s/To You/Dear sed/' <<< ''
Happy Birthday To You
Happy Birthday To You
Happy Birthday Dear sed
Happy Birthday To You

7
sed答案永远是赢家IMO :)
数字创伤

较短的答案似乎是51个字节,而不是您列出的52个字节
Taylor Scott

1
@TaylorScott,顶部的说明也适用于此:“(添加了1个字符,因为sed没有输入就无法工作。)”。
manatwork '18

嗯,这很有意义:)
泰勒·斯科特

30

C,73个字节

main(c){for(;c-5;)printf("Happy Birthday %s\n",++c-4?"To You":"Dear C");}

无关紧要的错误:应该为i++-3。(当前“亲爱的c”出现在第二行。)(虽然使用单个变量,我将其命名为“ c”。)
manatwork 2014年

常量固定,变量更改。有缩短代码的想法吗?
VX

抱歉,不知道要缩短它。C不是我的力量。(我发现了这个错误,因为即使您的当前分数对我来说也是如此令人难以置信,以至于我不得不尝试一下。;))
manatwork

12
难道不是“ Dear C”(大写)吗?
TRiG 2014年

我也想念那里的穿刺字符...
VX

27

蟒蛇,61 60 59

H="\nHappy Birthday to You"
print(H*3)[:60]+"Dear Python"+H

1
您可以保存1个字节- H="\nHappy Birthday to You"print(H*3)[:59]+" Dear Python"+H
Stretch Maniac

1
这是python 2.7还是3?
乔治

2
@George:Python 2.7,因为该print参数没有括号。
Falko 2014年

1
交互式解释器的输出计数吗?h="\nHappy Birthday to You";(h*3)[:60]+"Dear Python"+h
2014年

1
您可以通过删除之前的空格Dear并更改59为来节省更多空间60
2014年

26

sh,52

H()(echo Happy Birthday ${@-to You});H;H;H Dear sh;H

3
使用默认值参数扩展,仅53个字符:H()(echo Happy Birthday ${@:-to You});H;H;H Dear sh;H
manatwork 2014年

哦,很好@manatwork!
Digital Trauma 2014年

2
您可以在参数扩展中省略冒号-如果从未设置过参数,则可以使用冒号,同时:-还涵盖了设置但为空的情况

@professorfish很好-谢谢,我不知道!
Digital Trauma 2014年

@DigitalTrauma一个好地方看,如果你需要保存字符是wiki.bash-hackers.org/syntax/pe -有所有参数扩展语法的名单

22

ArnoldC,228个字节

Arnold Schwarzenegger唱歌...

IT'S SHOWTIME
TALK TO THE HAND "Happy Birthday to You"
TALK TO THE HAND "Happy Birthday to You"
TALK TO THE HAND "Happy Birthday Dear ArnoldC"
TALK TO THE HAND "Happy Birthday to You"
YOU HAVE BEEN TERMINATED

输出:

Happy Birthday to You
Happy Birthday to You
Happy Birthday Dear ArnoldC
Happy Birthday to you


@squeamishossifrage哈哈,已修复。
Wasi 2014年

16
也许您可以添加一个Ahnold Lisp!Hahpy Birfday将字符数减少
Compass


19

莎士比亚编程语言,3429字节

没有人会痴呆,无法参加SPL 的挑战赛,所以...

我自己的话,前一阵子。然而,有人被痴呆了。是的,是的,我知道。字节过多。但我认为SPL应该包含在此处。并且相信我,我为使该程序“投入使用”付出了巨大的努力,这就是为什么它有点重复并且使用几乎相同的词的原因(我本来可以遵循DLosc的建议,但是即使对我来说也太极端了) 。

A Happy Birth Day

Ajax, a hero
Ford, a man

          Act I: 1

          Scene I: 1

[Enter Ajax and Ford]

Ajax:
 You are nothing!

          Scene II: 2

Ford:
 Am I nicer than the sum of a big cow and a son?

Ajax:
 If so, we shall go to Scene V. You are as big as the sum of thyself and a cat!

          Scene III: 3

Ford:
 You are as red as the sum of a big red warm rich bold fair cat and a big rich fine son.
 Speak thy mind! You are as big as the sum of thyself and the sum of a cute fair fine
 rich cat and a hog! Speak thy mind! You are as big as the sum of thyself and the sum
 of a cute fair fine rich cat and a hog. Speak thy mind. Speak thy mind! You are as bold as
 the sum of thyself and the sum of a big fine fair cat and a cow. Speak thy mind! You are
 as big as a red old fair fine tiny cow. Speak thy mind! You are as old as the sum of
 thyself and the sum of a red old fair fine tiny cow and a big joy. Speak thy mind.
 You are as red as the sum of thyself and the sum of the sum of a red old fair fine
 tiny cow and a rich old red sky and a pig. Speak thy mind! You are as old as the sum
 of thyself and the sum of a big fine fair joy and a son. Speak thy mind. You are as
 red as the sum of thyself and a cute son. Speak thy mind! You are as cute as the sum
 of thyself and the sum of a bad fat vile pig and a fat bad lie. Speak thy mind! You are
 as fat as the sum of thyself and a vile evil war. Speak thy mind! You are as vile as the
 sum of thyself and the sum of a pig and a toad. Speak thy mind! You are as fair as the
 sum of thyself and the sum of a big fair hard fine son and a red fine fair joy. Speak
 thy mind! Are you as old as a big cow?

Ajax:
 If so, we shall go to Scene IV.

Ford:
 You are as big as a red old fair fine tiny cow. Speak thy mind! You are as old as the sum
 of thyself and the sum of the sum of a big red warm rich bold fair cat and a red old fair
 fine tiny cow and a bad hog. Speak thy mind! You are as big as the sum of thyself and the
 sum of a fat bad hog and a war. Speak thy mind! You are as big as a red old fair fine tiny
 cow. Speak thy mind! You are as old as the sum of thyself and the sum of a big red warm
 rich bold fair cat and a fat foul bad hog and a son. Speak thy mind. You are as fat as
 the sum of thyself and the sum of the sum of a big fair hard fine son and a big fine
 fair joy and a bad pig. Speak thy mind. 

Ajax:
 Let us return to Scene II.

          Scene IV: 4

Ford:
 You are as big as a red old fair fine tiny cow. Speak thy mind! You are as old as the
 sum of thyself and a big red warm rich bold fair cat and a warm sky. Speak thy mind.
 You are as fat as the sum of thyself and the sum of a red old fair fine tiny cow and a
 cat. Speak thy mind. You are as fat as the sum of thyself and a bad foul hog. Speak
 thy mind. You are as cute as the sum of thyself and the sum of a big fair hard fine
 son and a sky. Speak thy mind. You are as big as a red old fair fine tiny cow. Speak thy
 mind! You are as old as the sum of thyself and the sum of thyself and the sum of the sum
 of the sum of a red old fair fine tiny cow and a big fair hard fine son and a big joy and
 a son. Speak thy mind. You are as bad as the sum of thyself and the sum of a fat pig and a
 hog. Speak thy mind. You are as fat as the sum of thyself and a lazy pig. Speak thy mind.

Ajax:
 Let us return to Scene II.

          Scene V: 5

[Exeunt]

这一切的意义?

好的,如果您对所有这些工作方式感到好奇,请让我尝试解释一下我的理由。首先,变量。它们必须来自莎士比亚的戏剧,并且由于tharacter的数量很重要,因此我们必须选择较小的戏剧。因此,AjaxFord出现。声明后需要一个描述(被忽略,但仍然);我本可以用一个字母,但是。

第一幕,第一幕

var Ajax, Ford; Ford = 0;

我们将变量带入阶段,并Ajax告知Ford其值将为0。

第一幕第二场

if (Ford > 2*1+1) goto Scene V; Ford = Ford + 1;

OK,如果存储的值Ford大于3,程序将跳转到场景V;否则,程序将跳转到场景V。否则,其值将增加。

第一幕第三场

Ford = 2*2*2*2*2*2*1+2*2*2*1; print((char) Ford); Ford = Ford+2*2*2*2*1-1; print((char) Ford); Ford = Ford+2*2*2*2*1-1; print((char) Ford); print((char) Ford); Ford = Ford+2*2*2*1+1; print((char) Ford); Ford = 2*2*2*2*2*1; print((char) Ford); Ford = Ford+2*2*2*2*2*1+2*2*2*1+(-1); print((char) Ford); Ford = Ford+2*2*2*1+1; print((char) Ford); Ford = Ford+2*1; print((char) Ford); Ford = Ford+2*2*2*(-1)+2*2*(-1); print((char) Ford); Ford = Ford+2*2*(-1); print((char) Ford); Ford = Ford+2*(-1)+(-1); print((char) Ford); Ford = Ford+2*2*2*2*1+2*2*2*1; print((char) Ford); if (Ajax == 2*1) goto Scene IV; Ford = 2*2*2*2*2*1; print((char) Ford); Ford = Ford+2*2*2*2*2*2*1+2*2*2*2*2*1+2*(-1); print((char) Ford); Ford = Ford+2*2*(-1)+(-1); print((char) Ford); Ford = 2*2*2*2*2*1; print((char) Ford); Ford = Ford+2*2*2*2*2*2*1+2*2*2*(-1)+1; print((char) Ford); Ford = Ford+2*2*2*2*1+2*2*2*1+2*(-1); print((char) Ford); Ford = Ford+2*2*2*1+2*-1; print((char) Ford); goto Scene II;

荷载和线荷载。这个想法是弄乱存储在上的值Ford,进行大量的算术运算,以便获得所需字母的ASCII码,然后告诉编译器以字符形式输出该数字。那就是你的写作方式Happy Birthdayif这个场景有一个内部:想法是检查这是否是歌曲的第三句话;如果是的话,我们跳到第四场景;否则,我们会继续前进,写信to You。之后,我们跳回到场景II。

第一幕,第四场

Ford = 2*2*2*2*2*1; print((char) Ford); Ford = Ford+2*2*2*2*2*2*1+2*2*1; print((char) Ford); Ford = Ford+2*2*2*2*2*1+1; print((char) Ford); Ford = Ford+2*2*(-1); print((char) Ford); Ford = Ford+2*2*2*2*1+1; print((char) Ford); Ford = 2*2*2*2*2*1; print((char) Ford); Ford = Ford+2*2*2*2*2*1+2*2*2*2*1+2*1+1; print((char) Ford); Ford = Ford+2*(-1)+(-1); print((char) Ford); Ford = Ford+2*2*(-1); print((char) Ford); goto Scene II;

它的工作方式与上面的场景类似:想法是write Dear SPL

第一幕,第五幕

End.

就这样

不幸的是,我仍然没有找到可以测试的地方。


我认为您应该能够重复这样的单词fat fat fat fat cat。另外,我使用github.com/drsam94/Spl/blob/master/splc.py来编译我的spl代码。
clamchowder314 '16

16

Ruby,54个字节

我只是以为“嘿,还没有Ruby的答案”,但是随后一个出现了几秒钟。那好吧...

puts h="Happy Birthday to You",h,h[0,15]+"Dear Ruby",h

16

对PHP有何爱好?61 59 58字节

$s="
Happy Birthday";echo$t="$s to You","$t$s Dear PHP$t";

在运行中查看它@ http://sandbox.onlinephpfunctions.com/


1
将分配给$ t的赋值与其第一个输出结合起来:$s="\nHappy Birthday";echo$t="$s to You","$t$s Dear PHP$t";
manatwork 2014年

@manatwork很好的建议,谢谢!
MonkeyZeus 2014年

58
不。没有对PHP的热爱。曾经
假名称

具有短标签的相同字节数:<?=$t=($s="\nHappy Birthday")." to You","$t$s Dear PHP$t"?>
AmadeusDrZaius

1
将其替换为\n实际的换行符以保存字符。
Christoph'Apr

15

我只是不能只选择一种语言:/

脑后:68

4 ["Happy birthday ">2 ->![<0 "to You
"]<[<0 "Dear BrainBack
"]<1 -]

BrainBack是BrainFuck和Forth的结合,专为PCG挑战而设计Mar 7,2014

扩展的BrainFuck:79

{h|"Happy Birthday ">}{t|"to You
">}&h&t&h&t&h|"Dear Extended BrainFuck
">&h&t

EBF的生日是2010年7月16日

方案:96

(R5RS,球拍,R6RS REPL)

(map(lambda(e)(display"Happy Birthday ")(display(if e "to You\n" "Dear Scheme\n")))'(1 1 #f 1))

Scheme于197512月出生(NB:PDF)

佐佐茨:96

((:'R(\(l)(p'|Happy birthday |())(p(?(a l)'|to You|'|Dear Zozotez|))(?(d l)(R(d l)))))'(t t()t))

但是,用法语(86)进行此操作更合适:

((:'A(\(l)(p'|Joyeux anniversaire|())(p(a l))(?(d l)(A(d l)))))'(, , | Zozotez,| |.|))

输出:

Joyeux anniversaire,
Joyeux anniversaire,
Joyeux anniversaire Zozotez,
Joyeux anniversaire.

佐佐茨的生日是2011年7月19日


4
+1表示“生日快乐,亲爱的Brainfuck”,这可能是这里最费劲的语言名称。但是,该程序的大小只相当于父语言的等效语言的一小部分。对于Zozotez来说,法语听起来确实更好,尽管总的来说,我不太喜欢法国人将这个人的名字挤进这首歌的同一行。
级圣河

在您的Zozotez答案中,应该为Joyeux anniversaire à Zozotez
Beta Decay

2
@BetaDecay据我(法国)妻子说,应该没有这样的介词。法国维基百科同意。
Sylwester 2014年

14

死鱼(2610 2391字符)

这是什么?仅输出挑战?听起来像是Deadfish的工作!

iiisdsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiiiiiiiiooiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiioiioddddddddddddoddddodddoiiiiiiiiiiiiiiiiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddsdddddodddddodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddddsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiioiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiiiiiiiiooiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiioiioddddddddddddoddddodddoiiiiiiiiiiiiiiiiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddsdddddodddddodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddddsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiioiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiiiiiiiiooiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiioiioddddddddddddoddddodddoiiiiiiiiiiiiiiiiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiiiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioddddoiiiiiiiiiiiiiiiiioddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiiiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioddddoiiioiioiiioiiiiiiiiiiodddddddddddoddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiiiiiiiiooiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiioiioddddddddddddoddddodddoiiiiiiiiiiiiiiiiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddsdddddodddddodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddddsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiioiiiiiio

不幸的是,由于Deadfish仅输出整数,因此上面的代码输出了歌曲中每个字符的ASCII表示。

如果我们使用规范

错误不会被确认:shell只是添加了换行符!

那么我们可以将其降低到2391个字符:

iiisdsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiiiiiiiiooiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiioiioddddddddddddoddddodddoiiiiiiiiiiiiiiiiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddsdddddodddddodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddddsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiioiiiiiiofdddddddddddddddddddddddddddddddddddddddddddddoiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiiiiiiiiooiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiioiioddddddddddddoddddodddoiiiiiiiiiiiiiiiiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddsdddddodddddodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddddsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiioiiiiiiofdddddddddddddddddddddddddddddddddddddddddddddoiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiiiiiiiiooiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiioiioddddddddddddoddddodddoiiiiiiiiiiiiiiiiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiiiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioddddoiiiiiiiiiiiiiiiiioddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiiiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioddddoiiioiioiiioiiiiiiiiiiodddddddddddofddddddddddddddddddddddddddddddddoiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiiiiiiiiooiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiioiioddddddddddddoddddodddoiiiiiiiiiiiiiiiiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddsdddddodddddodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddddsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiioiiiiiio 

注意:Deadfish 实际上不是我最喜欢的语言,但是我无法抗拒:P。另外,在Deadfish中打高尔夫球本身也是一个有趣的难题。


19
对于“乐趣”的某些值。
查尔斯·伍德

13

JS,83个字节

h="Happy Birthday to You\n",console.log(h,h,h.replace("to You\n","Dear")+" JS\n",h)

或@IngoBürk的79个字节

h="Happy Birthday ",t="to You\n",console.log(h+t,h+t,h+"Dear Javascript\n",h+t)

或@kapep的71个字节

console.log(a=(b="Happy Birthday ")+"to You\n",a,b+"Dear Javascript\n",a)

或在控制台上运行此页面(42字节)

eval($("#answer-39759 code:first").text())

4
同样,它更短:(h='Happy Birthday ',t='to You\n';console.log(h+t,h+t,h+'Dear Javascript\n',h+t)您仍然可以使用它prompt来保存更多)
IngoBürk2014年

11
大声笑在最后一个代码段..:D
Optimizer

1
76:t='to you\n';console.log(h='Happy birthday',t+h,t+h,'dear JavaScript\n'+h,t)
NinjaBearMonkey

1
71:console.log(a=(b="Happy Birthday ")+"to You\n",a,b+"Dear Javascript\n",a)
kapex 2014年

3
改为改为alert((t=(h="Happy Birthday ")+'to You\n')+t+h+'dear EcmaScript\n'+t)
发出

11

R:70个字节

利用paste和向量回收。

writeLines(paste(rep("Happy Birthday",4),c(rep("to You",2),"Dear R")))

cat(paste(rep("Happy Birthday",4),c(rep("to You",2),"Dear R"),'\n'))
2014年

@germcd不太有效,因为cat在字符串之间添加了空格。因此,除了第一行外,您在每行的开头都带有一个空格。
bdzimmer

write(x,"")-> write(paste(rep("Happy Birthday",4),c(rep("to You",2),"Dear R")),"")68个字节。这是我的原始解决方案,其中73 p=paste;write(c(i<-p(h<-"Happy Birthday","to You"),i,p(h,"Dear R"),i),"")Vector回收再次击败了我。
Vlo 2014年

减少到66个字节`~`=rep;write(paste("Happy Birthday"~4,c("to You"~2,"Dear R")),"") tio.run/##K/r/...
尼克·肯尼迪

11

T-SQL,89 87字节

编辑:也许不应该疏通这些旧的东西,但是我只是注意到一个明显的变化,以回收几个字节。

使用STUFF删除字符串中不需要的部分,起始索引由FROM子句中的值乘以3来提供

SELECT STUFF('Happy Birthday to You  Dear SQL',N,8,'')FROM(VALUES(24),(24),(15),(24))S(N)

这一个很好!
TLama

这是一个出色的SQL解决方案,也是一个很好的技巧!
BradC

9

GNU DC,51岁

[Happy Birthday to You]d[Happy Birthday Dear dc]rdf

3
我也尝试过使用dc,但即使是几乎原始的版本也较短:[Happy Birthday To You]d[Happy Birthday Dear dc]rdf51个字符。
manatwork

今日热播@manatwork :)
Digital Trauma

3
由于这篇文章,我今天知道了dc的存在,它很棒。
卡勒布·保罗

9

Perl-58

say"Happy Birthday ".($_?"Dear Perl":"To You")for(0,0,1,0)

运行:

perl -E'say"Happy Birthday ".($_?"Dear Perl":"To You")for(0,0,1,0)'

纯娱乐:

perl -E'for(<HappyBirthday{0,1,2,3}>){s/B/ B/;s/2/ Dear Perl\n/;print s/\d/ To You\n/r}'

6
怎么say"Happy Birthday $_"for("to You","Dear Perl")[0,0,1,0]
2014年

@ core1024我不知道您可以使用数组来做到这一点,这太棒了。随意发布作为您自己的答案!
hmatt1 2014年

8

Python 507位元组

打印“”
生日-生日-快乐-生日
-至-Y ou = H appy-生日-D e
ar-P ython = Ha ppy-Bir t hda y -to- Y o uHapp y-
生日-至-Y ou = H app
y-生日-至-ou = H a ppy-B ir
“”“ .replace(” \ n“,”“)。replace(”“,”“)。replace(”-“,”“).replace(” =“,” \ n“)[:92]

没有赢得任何奖项...但是如果仔细看,会有一些ASCII艺术:

###### ############# ### ##############
########################
#### ##### ### ########################
###################
########## ##################

这不是一个认真的竞争者。
硕果累累

3
@ Challenger5是的,“但是,我也要对其他机智的作品进行投票,以鼓励他们(我也鼓励大家也这样做。)因此,尽管这是一场代码高尔夫比赛,但也欢迎简短回答”。
Alex

7

PowerShell- 69 64 59

1,1,0,1|%{"Happy Birthday "+("Dear $ShellId","To You")[$_]}

和91

$a,$b,$c="Happy Birthday.To You.Dear PowerShell".Split(".");1..2|%{"$a $b"};"$a $c";"$a $b"

和108

$a=@();$b,$c="To You.Dear PowerShell".Split(".");1..4|%{$a+="Happy Birthday $b"};$a[2]=$a[2]-replace$b,$c;$a

6

Ruby,56岁

x="Happy Birthday To You
"*4
x[59,6]="Dear Ruby"
puts x

你不能内联东西吗?
Optimizer

2
=以等号结尾的方法总是在等号后返回表达式的结果。如果我内联,它只会打印"Dear Ruby"String#[]=是一种方法)。
britishtea 2014年

1
>字符串中的换行符。好的,现在我完全相信红宝石只是伏都教魔法,作为农民,我应该坚持使用python。
sagiksp

6

Marbelous,151

根据输入是还是,Happy Birthday每次hb调用时都将打印print ,to you或者Dear Marbelous添加或添加。传递的大理石无法输出,因为它会卡在同步器中。01hb&0

03
00
02
01
hb
:hb
}0
=0&0
&1
&2//
746F20596F7544656172204D617262656C6F75730A
&0&0&0&0&0&0&1&1&1&1&1&1&1&1&1&1&1&1&1&1&2
486170707920426972746864617920

下面是board hb,十六进制已转换为ascii文本: 在此处输入图片说明


5

CJam,46个字节

4,{"Happy Birthday "\2="Dear CJam""to You"?N}%

在这里尝试。

4,                                             "Push [0,1,2,3].";
  {                                         }% "Map...";
   "Happy Birthday "                           "Push the string.";
                    \                          "Swap top two stack elements (string and
                                                array element)";
                     2=                        "Check equality with 2.";
                       "Dear CJam""to You"     "Push two more strings.";
                                          ?    "Select string based on result of 2=.";
                                           N   "Push a line break";

这将以下数组留在堆栈上:

["Happy Birthday " "to You" "\n" "Happy Birthday " "to You" "\n" "Happy Birthday " "Dear CJam" "\n" "Happy Birthday " "to You" "\n"]

程序的末尾将自动连续打印其内容。

或者,使用for循环并使用相同的字符数:

4{"Happy Birthday "I2="Dear CJam""to You"?N}fI

5
说谎者!!您最喜欢的语言是Ruby / Mathematica:P
Optimizer

1
@Optimizer当然不是Ruby,也许不是Mathematica,但我什至不确定。对于“真实”编程,我可能总是选择C / C ++ / C#。(我也很确定,您的是JS:P。)
Martin Ender 2014年

5
你得到了我:P:D
Optimizer

5

哈斯克尔:75

h="Happy Birthday "
y=h++"to You"
main=mapM_ print[y,y,h++"Dear Haskell",y]

ideone中的代码输出

Haskell一线:79

mapM_ print["Happy Birthday "++if x==3then"Dear Haskell"else"to You"|x<-[1..4]]

您可以在此处在线尝试一种班轮:http//tryhaskell.org/


1
一个可以刮掉一个角色的衬垫:mapM_(print.("Happy Birthday "++))["to You","to You","dear Haskell","to You"]
Alex Reinking 2014年

列表的理解非常糟糕
Alex

2
同样,从技术上讲,它应该putStrLn符合规格(您会收到双引号print
Alex Reinking 2014年

2
_没有必要的,因为main函数的返回值被扔掉-你只看到它在GHCI
傲haskeller

5

Var'aQ-121

"Happy Birthday " ~ a cher "to you\n" tlheghrar ~ b cher b tlheghrar a "dear Var'aQ" tlheghrar tlheghrar b tlheghrar cha'

1
卡普拉!+1可使用所有语言的Var'aQ!
WallyWest

5

GolfScript:54个字符

4,{"Happy Birthday "["To You""Dear GolfScript"]@2==n}%

样品运行:

bash-4.3$ golfscript.rb <<< '4,{"Happy Birthday "["To You""Dear GolfScript"]@2==n}%'
Happy Birthday To You
Happy Birthday To You
Happy Birthday Dear GolfScript
Happy Birthday To You

我只是注意到了。(尝试编写GolfScript代码约5到6个小时几乎没有副作用。)谢谢@MartinBüttner。
manatwork 2014年

1
生日快乐,亲爱的CodeGolf
丹尼斯

r 我不仅在编写它时很累,而且在修复它时也很累。谢谢@丹尼斯。
manatwork 2014年

5

T-SQL(符合MS标准):75

print stuff(replicate('Happy Birthday to You '+char(10),4),62,6,'Dear SQL')

不错的一个……希望我想到了:)
MickyT 2014年

好想法!通过替换节省9个字节+char(10)引号引起来的换行符,只需使返回部分成为字符串即可。
BradC

5

C#(75)(73)

使用System.Diagnostics为目的Debug.Print

升级到@Abbas的代码

string x="\nHappy Birthday ",y=x+"to You";Debug.Print(y+y+x+"Dear C#"+y);

升级到@Tyress'代码(83)(76)

for(int i=0;i++<4;)Debug.Print("Happy Birthday "+(i!=3?"to You":"Dear C#"));

输出:

Happy Birthday To You
Happy Birthday To You
Happy Birthday Dear C#
Happy Birthday To You

2
您可以使用String.Format和三元运算符保存几个字符。您也可以使它看起来i++<3
不太像
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.