# Sing Happy Birthday to your favourite programming language

Your favourite programming language has just had a birthday. Be nice and sing it the Happy Birthday song.

Of course you should accomplish this by writing a program in that language. The program takes no input, and writes the following text to the standard output or an arbitrary file:

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


You should substitute the bracketed part (and omit the brackets).

This is a code golf — shortest code wins.

## UPDATE

I'm glad that the question aroused great interest. Let me add some extra info about scoring. As stated originally, this question is a code golf, so the shortest code is going to win. The winner will be picked at the end of this week (19th October).

However, I'm also rewarding other witty submissions with up-votes (and I encourage everybody to do so as well). Therefore although this is a code-golf contest, not-so-short answers are also welcome.

## Results

Congratulations to Optimizer, the winner of this contest with his 42 byte long, CJam submission.

• Can we count the name of the programming language as one byte because it would only seem fair to people coding in a long-winded language such as JavaScript vs. someone doing it in C. We are really looking for most creative logic right? – MonkeyZeus Oct 13 '14 at 18:49
• Why all the upvotes for this despite all the downvotes for the Bonbon song? This is just as boring a challenge. – xnor Oct 14 '14 at 7:15
• I should probably mention that the song is copyrighted and distributing these programs may cause a DMCA – ratchet freak Oct 14 '14 at 14:38
• guys! Happy Birthday song is now in public domain!! – Optimizer Sep 23 '15 at 10:01
• At least one of the answers prints a leading newline. Is that allowed? – Dennis Jun 19 '16 at 21:32

# 05AB1E, 36 bytes

”ŽØ¢©”©" to You"«Ð®" Dear 05AB1E"«s»


TIO Nexus

Try it online!

Output:

Happy Birthday to You
Happy Birthday to You
Happy Birthday Dear 05AB1E
Happy Birthday to You


Explanation:

”ŽØ¢©”                                Push "Happy Birthday"
STACK: ["Happy Birthday"]
©                               Store in register w/o popping
" to You"«                     Append " to You"
STACK: ["Happy Birthday to You"]
Ð                    Triplicate the string
STACK: ["Happy Birthday to You", "Happy Birthday to You", "Happy Birthday to You"]
®                   Push "Happy Birthday" from register
STACK: ["Happy Birthday to You", "Happy Birthday to You", "Happy Birthday to You", "Happy Birthday"]
" Dear 05AB1E"«    Append " Dear 05AB1E"
STACK: ["Happy Birthday to You", "Happy Birthday to You", "Happy Birthday to You", "Happy Birthday Dear 05AB1E"]
s   Swap top two strings
STACK: ["Happy Birthday to You", "Happy Birthday to You", "Happy Birthday Dear 05AB1E", "Happy Birthday to You"]
»  Join by newlines


# BBC BASIC, 81 / 76 ASCII characters

Unfortunately, it's not possible to choose between strings within an expression, so the line endings are repetitively encoded in a DATA statement. On the other hand, when you read the last line, it does sound quite musical.

FORk=1TO4READa$PRINT"Happy Birthday ";a$:NEXT
DATAto You,to You,Dear BASIC,to You


We can, however, choose what substring to select from a given string, for a saving of 5 characters (note that k=3 evaluates to -1 when true):

FORk=1TO4PRINT"Happy Birthday ";MID$("Dear BASICto You",11+(k=3)*10,10):NEXT  # BBC BASIC, 69 ASCII characters A shorter way: a$="Happy Birthday "b$="to You"PRINTa$;b$'a$;b$'a$;"dear BASIC"'a$;b$

• I had no idea that you didn't need a colon for one-liners... – Beta Decay Oct 15 '14 at 18:14
• @BetaDecay according to the official syntax you do need the colon in most cases. But in practice BBC BASIC for Windows lets you get away without them. The original BBC Micro manual gave certain advice for improving the speed of your programs, of which I've taken in the following: use lowercase variable names, and eliminate as many unnecesary characters as possible. – Level River St Oct 15 '14 at 18:32

# VBA 99

Why VBA? Why not?

Sub H(): For i = 0 To 3: MsgBox "Happy Birthday " & IIf(i = 2, "Dear VBA", "to You"): Next: End Sub


Ungolfed

Sub H()
For i = 0 To 3
MsgBox "Happy Birthday " & IIf(i = 2, "Dear VBA", "to You")
Next
End Sub

• Still shorter than C# :D – Brandon Oct 17 '14 at 12:22
• For what it's worth (2.5yrs later), you can remove the auto-formatting to get it down to 86 bytes: Sub H():For i=0To 3:MsgBox"Happy Birthday " &IIf(i=2,"Dear VBA","to You"):Next:End Sub – Engineer Toast Apr 27 '17 at 13:03
• @EngineerToast I don't feel like that's legit. The only environment that compiles that code enforces those spaces. – RubberDuck Apr 27 '17 at 13:31
• I used to think that, too, so I did some searching on meta and found a post that made sense to me saying why autoformatting should be discounted. It's not wrong either way but I somewhat enjoy finding all the white space I can remove from VBA and have it still work. – Engineer Toast Apr 27 '17 at 14:02
• @EngineerToast I'll actually buy that, because the official grammar doesn't require the white space. – RubberDuck Apr 27 '17 at 14:05

# Common Lisp (62 60 chars)

(format t"~@{Happy Birthday ~[to You~;dear CL~]~%~}"0 0 1 0)


# Output

Happy Birthday to You
Happy Birthday to You
Happy Birthday dear CL
Happy Birthday to You

• Is the space before and after the string needed? – kay Oct 21 '14 at 1:40
• @Kay No, the space is not needed. I removed it, which saves 2 chars. Thanks. – coredump Oct 21 '14 at 5:58

Qt 5.4 qmake pro file, 119 bytes

Since the winner has already been announced, I thought I'd give a try for the witty category.

O=$$escape_expand(\n) A=Happy Birthday B=$$A to you$$O CONFIG(debug,debug|release){log($$A dear qmake$$O)}log($$B)


This abuses qmake horribly.

qmake under default settings will parse a script 3 times over. For debug, release, and a build_pass. So we just let it throw out the "Happy Birthday" for all logs, with an extra "To you..." when a debug makefile is being generated.

Happy Birthday to you
Happy Birthday to you
Happy Birthday dear qmake
Happy Birthday to you


# Retina, 47 495052 bytes

The program is encoded as ISO-8559-1 (which the official interpreter accepts). The leading newline is significant.


¶¶x¶

Happy Birthday to You
.{27}u
Dear Retina

Try it online.

# Explanation

Step 1: Replace the (empty) input with “newline, newline, x, newline”.

Step 2: In between every character, insert Happy Birthday to You. We now have:

Happy Birthday to You
Happy Birthday to You
Happy Birthday to YouxHappy Birthday to You
Happy Birthday to You


Step 3: replace a 28-character string ending in u and not containing a newline with Dear Retina. The only occurrence of that is to YouxHappy Birthday to You.

# Reng, 66 bytes

Noncompeting.

A"uoY ot yadhtriB yppaH"¤ao;A"gneR raeD yadhtriB yppaH ~"S0gO0gao;


Simple enough. A is 10, or a newline. "uoY ot yadhtriB yppaH" pushes that string, ¤ duplicates the string, ao; outputs everything. The second part is more interesting. "A"gneR raeD yadhtriB yppaH ~" pushes that string. S pushes 28, and 0g sets the character at (0, 28) to the top of stack, or a ~, the end program signal. This sets the last A to a tilde. Then, O0g sets the character at(0, 24) to a space/nop, removing the duplicate stack command. We print the third line using ao;. Then, we wrap around to the beginning of the line and print the last line again.

Here's a GIF, because who doesn't like those?

## Java, 127 125 bytes

class h{public static void main(String[]a){String b="\nHappy Birthday ",d=b+"to You";System.out.print(d+d+b+"Dear Java"+d);}}


However, if you ignore all of the excess stuff, it is only 82 80 bytes:

String b="\nHappy Birthday ",d=b+"to You";System.out.print(d+d+b+"Dear Java"+d);


Oh, and it starts with a newline, saving 2 bytes.

• output is not exactly as required, since there's an extra line at the start – Supuhstar Oct 17 '14 at 1:13
• @Supuhstar It merely says to output the song happy birthday. It makes no requirement for excess newlines/whitespace. – Stretch Maniac Oct 17 '14 at 2:56
• it says "writes the following text to the standard output or an arbitrary file:"... so... maybe you could stretch that to include extra bits? It doesn't sound like this is the intended answer, though. – Supuhstar Oct 17 '14 at 3:02
• I'm not exactly sure what you mean, but System.out.println is a standard output. – Stretch Maniac Oct 17 '14 at 3:04
• I don't mean the output method, but the actual output, which starts with a blank line – Supuhstar Oct 17 '14 at 3:14

# Excel VBA, 687 686 686 681 Bytes

From the problem statement:

However, I'm also rewarding other witty submissions with up-votes (and I encourage everybody to do so as well). Therefore although this is a code-golf contest, not-so-short answers are also welcome.

## Code

Full subroutine that takes no input and outputs a happy birthday song for VBA onto the range [A1:CM23] of the ActiveSheet object.

Global l
Sub a
Cells.RowHeight=48
For l=0To 3
p[A1:A5,B3,C1:C5,F1,E2:E5,G2:G5,F3,I1:I5,J1,K2,J3,M1:M5,N1,O2,N3,Q1:Q2,R3:R5,S1:S2]
If l-2Then p[BI1:BK1,BJ2:BJ5,BN1,BM2:BM4,BN5,BO2:BO4,BU1:BU2,BV3:BV5,BW1:BW2,BZ1,BY2:BY4,BZ5,CA2:CA4,CC1:CC4,CD5,CE1:CE5]Else p[BI1:BI5,BJ1,BK2:BK4,BJ5,BM1:BM5,BN1:BO1,BN3,BN5:BO5,BR1,BQ2:BQ5,BS2:BS5,BR3,BU1:BU5,BV1,BW2,BV3,BW4:BW5,CC1:CC4,CD5,CE1:CE4,CG1:CG5,CH1,CI2,CH3,CI4,CH5,CL1,CK2:CK5,CM2:CM5,CL3]
Next
End Sub
Sub p(r)
r.Offset(6*l).Interior.Color=0
End Sub


# JavaScript, 74 73

for(i=5;--i;)console.log('Happy birthday',i-2?'to you':'dear JavaScript')


Thanks to Dancrumb for the byte-saving tip. It would be 68 67 bytes if I could use 4 alerts instead of newlines.

for(i=5;--i;)alert('Happy birthday',i-2?'to you':'dear JavaScript')

• You can shave off a byte with: for(i=5;--i;)console.log('Happy birthday',i-2?'to you':'dear JavaScript') – Dancrumb Oct 13 '14 at 16:15
• If you want alert(), then use only 1, based on my comment at the other JavaScript answer. That will be 71 character without alert() flood. – manatwork Oct 13 '14 at 16:26
• You could also avoid the loops and let the output just be the expression itself (which is true on newer consoles): (a="\nHappy Birthday")&&(b=a+" to You")&&b+b+a+" Dear JavaScript"+a (67 too). – AmadeusDrZaius Oct 18 '14 at 19:19

## J (44)

2|.'Happy birthday ',"1'dear J',>3#<'to you'


# Swift, 83

Run this in Xcode Playground

let h="\nhappy birthday"
let t=" to you"
let f=h+t+h+t+h+" dear Swift"+h+t
print(f)

• If you put the space after happy birthday, you can get rid of the two in to you and dear Swift, saving you one byte – Beta Decay Oct 15 '14 at 6:11
• If you declare all 3 variables on the same line, you can save 8 bytes. – NobodyNada Oct 18 '14 at 20:56

## Groovy (64)

4.times{println"Happy Birthday ${it==2?'Dear Groovy':'to You'}"}  Powershell one liner: 73 71 1..4|%{"Happy Birthday$(if($_-eq3){"Dear Powershell"}else{"to You"})"} • You could shrink this to 71 if you did $_-eq3 – SomeShinyObject Oct 16 '14 at 13:06

APL: 45

4 23⍴'Dear APL',⍨61⍴'Happy birthday to you  '


Explanation:

61⍴ reapeats the string up to length 61, after which "Dear APL" is concatenated (,)

Note that ⍨ inverts arguments, so it's added at the end.

4 23⍴ just makes a matrix 4x23 using the string on the right, starting from the beginning of the string each time it reaches the end.

# Pyth, 42

V4+"Happy Birthday "?"to You"nN2"Dear Pyth


Demonstration:

$pyth -c 'V4+"Happy Birthday "?"to You"nN2"Dear Pyth' Happy Birthday to You Happy Birthday to You Happy Birthday Dear Pyth Happy Birthday to You  How it works: V4 sets up a for loop, with N iterating over 0, 1, 2, 3. Then, we create the string starting with "Happy Birthday ", and ending with "to You" if N does not equal 2 (nN2 calculates this), or ending with "Dear Pyth" otherwise. Exact tie with CJam - language name and character count. Alternative, 43 character solution: J"Happy Birthday to You"JJ+<J15"Dear Pyth"J  It's one character longer because it needs an end quote. • Aren't the V and N implemented after the question was asked ? – Optimizer Oct 21 '14 at 19:38 • @Optimizer No, they were added a while ago. Looking back at the commit log, they were added on August 21st, in a commit called: Pyth 2.1.0 - Changes to -;\AcPUVXz Out of curiosity, what gave you that impression? – isaacg Oct 21 '14 at 19:50 • Your recent Pyth tips answer left me thinking that it is something new and u always keep saying that you keep on adding features :). – Optimizer Oct 21 '14 at 19:56 • @Optimizer Ah - while I do add new things, I'm also trying to give general programming tips on that page, which cover everything in Pyth. – isaacg Oct 21 '14 at 20:21 # Julia, 7567 65 characters a,b,c="Happy Birthday ","To You\n","Dear Julia\n";print("$a$b$a$b$a$c$a$b") a="Happy Birthday";b=("$a To You\n");print("$b$b$a Dear Julia\n$b")

a="Happy Birthday To You\n";print("$a$a$(a[1:15])Dear Julia\n$a")

Just for fun, here is an ungolfed version, with a loop (114 characters):

for i = 1:4
a,b,c = "Happy Birthday ","To You","Dear Julia"
i != 3 ? println("$a$b") : println("$a$c")
end


# Casio CFX-9850G, 121 bytes 96

Just for the fun of it, the Happy Birthday song for the CFX-9850G graphing calculator.

Some instructions are just displayed as multiple bytes, but as far as I know they are encoded as 1 or 2 bytes. I marked them with colors. Edit: I checked the memory, so the program uses 121 bytes in the calculator.

The song text would not fit in a line, especially line 3 because in text mode the calculator can only display 7 rows and 21 columns. So I print the lyrics in graphing mode, which uses a tiny font.

Here is the output:

# Bubblegum, 42 bytes

0000000: f3 48 2c 28 a8 54 70 ca 2c 2a c9 48 49 ac  .H,(.Tp.,*.HI.
000000e: 54 28 c9 57 88 cc 2f e5 22 4a d4 25 35 b1  T(.W../."J.%5.
000001c: 48 c1 a9 34 29 29 27 35 bd 34 17 bb 1e 00  H..4))'5.4....


Note that this answer is non-competing, since Bubblegum is a lot younger than this challenge.

# Fishing, 116 bytes

v+CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
Happy Birthday P{to YouN}P{N}P{{Dear FishingN}}P{N

• I've posted a few questions, but here's my first answer! – Arcturus Oct 9 '15 at 23:25

# Seriously, 59 57 bytes (non-competitive)

"Happy Birthday to You";"Happy Birthday Dear Seriously"@;

Explanation

Push "Happy Birthday to You", duplicate, push "Happy Birthday Dear Seriously", rotate the two top elements, duplicate, and implicit popping and printing.

• 57 bytes: "Happy Birthday to You";"Happy Birthday Dear Seriously"@; – Mego Jan 8 '16 at 4:24

# ///, 48 bytes

/U/Happy Birthday //T/Uto You/T
T
UDear \/\/\/
T


(to You
)SSS


I was hindered by Underload's lack of stack manipulation commands. I had to push stuff in a strange order and swap a bit more than I would have preferred, but oh well...

Stack trace:

(...) | (to You)
:     | (to You)(to You)
(...) | (to You)(to You)(Happy Birthday )
:S    | (to You)(to You)(Happy Birthday )         ; output "Happy Birthday "
~     | (to You)(Happy Birthday )(to You)
S     | (to You)(Happy Birthday )                 ; output "to You"
:S    | (to You)(Happy Birthday )                 ; output "Happy Birthday "
~     | (Happy Birthday )(to You)
:S    | (Happy Birthday )(to You)                 ; output "to You"
~     | (to You)(Happy Birthday )
:S    | (to You)(Happy Birthday )                 ; output "Happy Birthday "
(...) | (to You)(Happy Birthday )(Dear Underload)
S     | (to You)(Happy Birthday )                 ; output "Dear Underload"
S     | (to You)                                  ; output "Happy Birthday "
S     |                                           ; output "to You


# Brainfuck, 593 characters

Used this

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


# C++, 135 bytes

Great thanks to Steadybox and DJMcMayhem for shortening this code by 55 characters! :)

#include<iostream>
#include<string>
std::string s="Happy Birthday ",t="to you\n",u="Dear C++\n";int main(){std::cout<<s+t+s+t+s+u+s+t;}

• You can use + instead of <<. – DJMcMayhem Jan 11 '18 at 17:58
• Welcome to PPCG! You can remove the space from between #include and <headerName>. Also, you can declare the strings in one go so you don't have to repeat the string. (After that using the std:: prefix is shorter than using namespace std;, too). Like this. – Steadybox Jan 11 '18 at 18:11

# Lua: 91 72 characters

First pass:

for i=1,4 do io.write'Happy Birthday 'if i==3 then print'Dear Lua'else print'to You'end end


Demo

Even smaller:

for i=1,4 do print('Happy Birthday '..(i==3 and'Dear Lua'or'to You'))end


Demo

# TI-BASIC: 65

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


In TI-BASIC, all built-in commands (even multi letter ones) are either one or two bytes on the calculator. The size I used represents the (minimum, since names take space) space taken by this code on my TI-84+SE running OS version 2.53MP. Seemingly wrong syntax (unclosed strings) is intentional.

# TI-68k: 90

:h()
:Prgm
:"Happy Birthday to You"→a
:Disp a,a,mid(a,1,15)&"Dear TI-68k",a
:EndPrgm


Again, the size I used is the minimum real size on the calc (in this case, a TI-92).

## R, 69 chars

for(i in 1:4)cat('Happy Birthday',ifelse(i==3,'Dear R','to You'),'\n')


Or

for(i in 1:4)cat('Happy Birthday',if(i==3)'Dear R' else 'to You','\n')


All output:

Happy Birthday to You
Happy Birthday to You
Happy Birthday Dear R
Happy Birthday to You


Otherwise with 66 characters there was, without the for loop:

a=rep('to You',4);a[3]='Dear R';cat(paste('Happy Birthday',a,'\n'))


But it outputs:

Happy Birthday to You
Happy Birthday to You
Happy Birthday Dear R
Happy Birthday to You


# C#

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


Console (75):

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


Ungolfed:

string x = "\nHappy Birthday ";
string y = x + "to You";

(y + y + x + "Dear C#" + y).Dump();

//Console
Console.Write(y+y+x+"Dear C#"+y);


# Rust, 98 bytes

fn main(){for i in range(0i,4){println!("Happy birthday {}",match i{2=>"dear Rust",_=>"to you"})}}

• Suggest 0..4 instead of range(0i,4) – ceilingcat Nov 8 '17 at 22:13

## PHP 6763 62

echo$z=($s="Happy Birthday").$t=" to You ","$z$s Dear PHP$z";


EDIT: As @manatwork pointed out, without the second echo I have 4 chars less!!

EDIT2: Other improvement according to @manatwork

• Nice one. But you not need a separate echo to have the earlier set variables available. Make the 2nd line: ","$z${s}Dear PHP. – manatwork Oct 14 '14 at 12:30
• @manatwork great suggestion! – Alessandro Oct 14 '14 at 12:34
• You can spare 1 more character by getting rid of those braces around variable \${s}. If you add the middle space to the both second half lines instead of the first half line, the length increases by 1 character, but you will be able to remove the braces, sparing 2 characters: pastebin.com/Qw7dWHGs – manatwork Oct 14 '14 at 12:35
• @manatwork I didn't got this... If I add the middle space to both the second half lines (before "to You" and before "Dear PHP") then I'm adding 2 chars and removing the brackets I have the same count – Alessandro Oct 14 '14 at 12:39
• Now: "Happy_" + "You" + "Dear", proposed : "Happy" + "_You" + "_Dear". So actually one of them you move and add just one new. – manatwork Oct 14 '14 at 12:44