# 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

## Visual FoxPro - 77

Not really my favorite language, but makes golfing somewhat interesting. Here is my greetings to it:

a="Happy Birthday "
b="to You"
?a+b
?a+b
?a+"Dear "+_screen.Caption
?a+b


This abuses the fact that _screen.Caption (the main window title) initially contains Microsoft Visual FoxPro, handy here. If I'm allowed to call the language by its "friendly name", I can just replace that for "Fox" and save 10 characters.

# Lua, 96 bytes

I was trying to be cool about this and make use of all the best Lua tricks I know but the guy who wrote a simple for loop with an if i==3 beat me by 20+ bytes >.<

Still, I think this is pretty cool in terms of Golfing:

a='Happy Birthday to you\ndear Lua\n'print(a:sub(0,-10):rep(3):sub(0,-8)..a:rep(2):sub(23,-10))


I was looking at recursively building the string a from a number using string.char() but I couldn't compress it anywhere near the length of a='Happy Birthday to you\ndear Lua\n'

0..3|%{"Happy Birthday "+("to You","Dear PowerShell")[$_-eq2]}  # Delphi, 154146 139 uses{$APPTYPE CONSOLE}SysUtils,StrUtils;var i:byte;begin
for i:=0to 3do WriteLn('Happy birthday '+IfThen(i=2,'dear Delphi','to you'))end.

• Which Delphi version is this? I never met one with such Output parameter. And better choose another integer type, with a shorter name. For example Byte. – manatwork Oct 16 '14 at 15:17
• An insignificant bug: the 'to you' and 'dear Delphi' should be reversed. – manatwork Oct 16 '14 at 15:27
• Some minor shortening which work in FreePascal: move the directive between uses and the first unit name to be able to remove the space (1 char); remove unnecessary newline characters (3 chars); remove the ; before end (1 char); remove the space characters between numeric literals and the following keywords (2 chars). See whether any of those works in your Delphi too. – manatwork Oct 16 '14 at 15:34
• @manatwork, thank you for your suggestions, it's Delphi XE2. – R-D Oct 17 '14 at 7:19
• There's no need for Output,. – TLama Oct 20 '14 at 23:08

# TeX - 70

\def\h{Happy Birthday }\def\y{to You}\h\y

\h\y

\h Dear TeX

\h\y\bye


Note that the line breaks are intentional and actually required.

# LaTeX, 182

This isn't intended to be a serious competitive entry, but just to do something fun. Therefore, disregard the char count. I don't need any golfing tips for this, because it is intentionally ungolfed.

\documentclass{article}
\newcommand{\h}[1]{Happy Birthday to {#1}}
\newcommand{\g}{\h{You}}
\begin{document}
\begin{verse}
\g \\
\g \\
\h{\LaTeX} \\
\g \\
\end{verse}
\end{document}


## C (74 characters)

main(i){for(i=4;i;)printf("Happy birthday %s\n",i---2?"to You":"Dear C");}


## Python 2 (72 characters)

for k in range(4):print"Happy birthday",k==2 and"Dear Python"or"to You"


Python 3 would need parentheses around the printed string, so two character more, so 74.

for($i=4;$i;)echo"Happy birthday ".($i---2?"to You\n":"Dear PHP\n");  • In C, i---2 saves a character. Also {} after for isn't needed. – ugoren Oct 20 '14 at 9:32 # Cardinal, 11310788 82 characters I fixed the errors in the original interpreter, so the operators work as specified. This enabled me to shrink down the code by another 19 25 characters: 4th version: v8888#;++"lanidraC raeD " < 8%+++>>"Happy Birthday"-jv^ >8888@^ ;"uoY oT "<  Output, using my interpreter fixes: Executing program.. Happy Birthday To You Happy Birthday To You Happy Birthday Dear Cardinal Happy Birthday To You Execution complete. >  Second version, saving 6 chars: I changed the o’s and O’s to v^<> because the available interpreter has some errors with the handling of the rotation operators o and O, j and J and some other errors. One has to use the wrong rotation operators to make it work, but I prefer using a version that works according to specification. The length of the code stays the same. This version works properly with the interpreter provided at the link given at the bottom of my comment: (107 characters) %->"Happy Birthd"v x ^D+;"uoY oT ya"< >"Happy Birthday D"v v"ppaH";"lanidraC rae"< >"y Birthday To You"@  Output, using the "original" faulty interpreter: Executing program.. Happy Birthday To You Happy Birthday To You Happy Birthday Dear Cardinal Happy Birthday To You Execution complete. >  You can test the program if you save it as txt file and drag it onto the interpreter exe for Windows. http://esolangs.org/wiki/Cardinal Here is the interpreter: http://floatation.webs.com/Cardinal.zip ## CMD - 84 Bytes cmd/v/c"set 1=to You&set 2=Dear CMD&for %a in (1,1,2,1)do @echo Happy Birthday !%a!"  # jq: 54 52 characters (49 characters code + 3 characters command line option.) 0,0,1,0|"Happy Birthday "+["to You","Dear jq"][.]  Sample run: bash-4.3$ jq -n -r '0,0,1,0|"Happy Birthday "+["to You","Dear jq"][.]'
Happy Birthday to You
Happy Birthday to You
Happy Birthday Dear jq
Happy Birthday to You


On-line test (Passing -r through URL is not supported – check Raw Output yourself.)

# Vim, 90 45 bytes

i
Happy Birthday to you
[ESC]
$b = 'to You' "$a$bn$a$bn$($a)Dear PowerShelln$a$b"  ## Clojure : 87 chars Golfed: (let[h"Happy Birthday "s(str h"to You\n")t(str h"Dear Clojure\n")](print(str s s t s)))  Ungolfed: (let [ h "Happy Birthday " s (str h "to You\n") t (str h "Dear Clojure\n") ] (print (str s s t s)))  • Or 81 with the similar (let[h"Happy Birthday "s"to You\n"t"Dear Clojure\n"](map #(print h %)[s s t s])) – tjb1982 Oct 16 '14 at 13:53 # C: 87 #define p(a)printf("Happy birthday %s\n",a?a:"to you"); main(){p(0)p(0)p("dear C")p(0)}  Demo Compiles fine, but since it doesn't return, it might not exit correctly. If you want it to return 0, it'll cost another seven characters: #define p(a)printf("Happy birthday %s\n",a?a:"to you"); main(){p(0)p(0)p("dear C")return!p(0)}  Demo # Burlesque - 55 Characters "Happy Birthday to You"4.*g_15.+"Dear Burlesque".+2iauN  Test it here. • "Happy Birthday " "to You"4.*"Dear Burlesque"3ia?+uN would be a shorter version. – mroman Sep 25 '15 at 11:45 Python 85 [print('Happy Birthday %s'%('dear Python' if x==2 else 'to you')) for x in range(4)]  • The if/else idiom can be generally shortened to a list selection: ['to you','dear Python'][x==2]. Instead of string formatting %, you can just use string concatenation. Take a look at some Python golf tips: codegolf.stackexchange.com/questions/54/… – xnor Oct 14 '14 at 7:05 # Cobra - 78 class P def main print (t=(l='Happy Birthday ')+'to You\n')+t+l+'Dear Cobra\n'+t  Scala 89 (also it is not my favourite) (1 to 4).map{i=>"Happy Birthday "+(if(i==3)"dear SCALA" else "to You")}.foreach{println}  Maybe it could be less, it is just a default example, so feel free to improve. Regarding Java: If ignoring the excess stuff it is also possible to do a "import static java.lang.System.*;" and then use out.println. So something like this is possible (87 chars): int i=0;while(i<=3){out.println("Happy Birthday "+((i==2)?"dear Java":"to you"));i++;}  (also it is longer than the solution from Stretch Maniac - see https://codegolf.stackexchange.com/a/39768) # Befunge: 103  >"yadhtriB yppaH"67+>:#,_1g:"0"-v 2^_@#-"0"g20p10-1,,,,,,," to You"_1+01p"egnufeB raeD ">:#,_"0"02p# 1  ## Railo CFML (79 characters) for(i=1;i<5;i++){writeoutput("<br>Happy Birthday "&(i<>3?"to you":"dear CF"));}  ## Just having some fun creating a ridiculous mess:  variables.endings = ["H,a,p,p,y, ,B,i,r,t,h,d,a,y, ,t,o, ,y,o,u","H,a,p,p,y, ,B,i,r,t,h,d,a,y, ,t,o, ,y,o,u","H,a,p,p,y, ,B,i,r,t,h,d,a,y, ,d,e,a,r, ,C,o,l,d, ,F,u,s,i,o,n,n,n,n,n","H,a,p,p,y, ,B,i,r,t,h,d,a,y, ,t,o, ,y,o,u"]; variables.iVerse = ''; for (i = 1; i <= ArrayLen(variables.endings); i++) { variables.iLine = ''; for (i2 = 1; i2 <= ListLen(variables.endings[i]); i2++) { iLine = iLine & ListGetAt(variables.endings[i],i2); } variables.iVerse = variables.iVerse & variables.iLine; if (i < ArrayLen(variables.endings)) { variables.iVerse = variables.iVerse & "<br />"; } } writeOutput(variables.iVerse);  • I know it's a little obvious what language this is, but please, describe what language you used and the character count of your code. Also, try to shorten it as much as you can. – g.carvalho97 Oct 13 '14 at 22:57 • @g.carvalho97 I was having too much fun, sorry. I'll fix it. – Regular Joe Oct 13 '14 at 23:01 # Bc: 62 characters (This demonstrates the language's only golfing strength: string literals are displayed even without the print statement.) while(i++<4){"Happy Birthday " if(i-3)"To You "else"Dear bc "}  Sample run: bash-4.3$ bc <<< 'while(i++<4){"Happy Birthday "
> if(i-3)"To You
> "else"Dear bc
> "}'
Happy Birthday To You
Happy Birthday To You
Happy Birthday Dear bc
Happy Birthday To You


# Python 3 - 61

Based on @Falko's answer I made one for Python 3.3. I slightly improved his code by removing the space at the beginning of "Dear Python" and using the space between 'Birthday' and 'to'.

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


Total number of characters is 60 61.(thanks for the recount @manatwork)

### Edit:

Two slightly different approaches, all with the same number of characters:

T="\nHappy Birthday to You"
print(T*2+T[:-6]+"Dear Python"+T)


or

print(T*2+T[:16]+"Dear Python"+T)


BTW: I would like to post this as a comment, but I do not have the rep.

• Sure about the 60 characters? Seems 61 to me. – manatwork Oct 14 '14 at 9:28
• @manatwork: you are right. Somehow my character counter gave the wrong output. It is also logic that I loss one character compared with Falko, because I need two parentheses and win one character by changing the "Dear Python" phrase. – Hennep Oct 14 '14 at 9:33