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.

  • 2
    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
  • 14
    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
  • 10
    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
  • 12
  • 4
    At least one of the answers prints a leading newline. Is that allowed? – Dennis Jun 19 '16 at 21:32

176 Answers 176

up vote 45 down vote accepted

CJam, 46 42 bytes

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

How it works:

"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";

This leaves the stack as following at the end of the code:

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

which are printed automatically to output as

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

Try it here (Copy the code and run it)

  • does the "first 15 characters" thing come from the F? is that how it knows the number 15? – vijrox Jun 30 '15 at 21:33
  • 1
    Yeah, a-f are 10-15. – Jacob Jul 1 '15 at 3:31

LOLCODE: 109 (105 with "correct" spelling)

LOLCODE is not a great language for golfing, especially since you lose all the beauty and expressiveness when shortening the code.

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

Test it using loljs

This is my preferred rendition, weighing in at 187 characters (spaces added for clarity):

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
  • 14
    I just knew there'd be a LOLCODE answer to this. BTW, kan u wryt n lwrcase insyd t kwotez? KTHXBYE. – Level River St Oct 15 '14 at 18:38
  • 1
    I tried writing a LOLCODE answer to another challenge a while back, but it's too verbose for code golfing, and it lacks decent data structures and the ability to create complex functions, so that rather limited my efforts! – i alarmed alien Oct 16 '14 at 20:30
  • 3
    This answer has given me an urge to download LOCODE and actually learn it properly. – Pharap Oct 18 '14 at 5:53
  • 1
    This is great!! – cybermonkey Oct 20 '14 at 15:35

Mathematica- barcode birthday wishes--way too many bytes

This prints the verses and reads them aloud.

happy birthday

Happy Birthday to You
Happy Birthday to You
Happy Birthday Dear Mathematica
Happy Birthday to You

StringReplace replaces each comma with a NewLine. Barcodes cannot contain control characters.

  • 11
    I can't see a barcode button on my keyboard! How can I test this? – matsjoyce Oct 20 '14 at 15:49
  • 15
    I love that there's a 10 in the barcode (bottom right corner), seeing that BarcodeRecognize was introduced in Mathematica 10. ^^ – Martin Ender Oct 23 '14 at 10:54
  • Yes! I hadn't noticed that. – DavidC Oct 23 '14 at 12:49
  • 11
    I actually scanned this with a QR code reader. It has extra spaces after every comma, couldn’t you save bytes if you— oh, wait. Never mind. – Timwi Jan 8 '16 at 17:41

TI-Basic, 53 bytes

Well, since everyone is putting their favorite programming language up, I might as well add one of my old favorites. I spent a lot of time over the years (before I graduated to actual programming languages) typing commands into a window half the size of a smart phone.

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

My calculator doesn't support lowercase letters, and the only variables that can be strings are Str1, Str2 etc.

  • Which flavor of TI-Basic? I got really familiar with it on the TI-84. – Jesan Fafon Oct 14 '14 at 16:38
  • 7
    Always nice to see TI-Basic. This appears to be standard 8x TI-Basic, where any expression is automatically stored to Ans, which can be used a weird and hard-to-follow optimization strategy. I also got started programming with this awesome language. – codebreaker Oct 14 '14 at 18:44
  • 3
    Note to editors: can you post any changes (in this case loss of 8 chars) in the comments rather than just editing it? That would make me feel like this is still my answer. – Stretch Maniac Oct 14 '14 at 19:58
  • 2
    +1!! that's how i learned to program too. I built Tron for the TI-83 :D it was quite slow though, thus not fun. – Nacht Oct 15 '14 at 22:42
  • 2
    Haha that's awesome. I made a Blackjack game for the TI-83. In the process I learned all the rules of Blackjack quite intimately. – thomasrutter Oct 18 '14 at 22:08

Sed, 60 55 bytes

(1 character added because there is no way to make sed to work without input.)

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

Certainly not a winner, posted to demonstrate sed's rare s/// feature of replacing just the nth occurrence.

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 (shorter but not interesting): 52 characters

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

Sample run:

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
  • 6
    sed answers are always winners IMO :) – Digital Trauma Oct 13 '14 at 16:42
  • The shorter answer appears to be 51 bytes, rather than the 52 you have listed – Taylor Scott Jul 26 at 14:54
  • 1
    @TaylorScott, the explanation at the top applied there too: “(1 character added because there is no way to make sed to work without input.)”. – manatwork Jul 26 at 15:10
  • Ahh, that makes sense :) – Taylor Scott Jul 26 at 15:13

C, 73 bytes

main(c){for(;c-5;)printf("Happy Birthday %s\n",++c-4?"To You":"Dear C");}
  • Insignificant bug: should be i++-3. (Currently the “Dear c” appears in the 2nd line.) (While using a single variable, I would name it “c”.) – manatwork Oct 13 '14 at 16:02
  • constant fixed, variable changed. Any idea to shorten the code? – V-X Oct 13 '14 at 16:08
  • Sorry, no idea to shorten it. C is not my strength. (I found the bug because even your current score is so unbelievable to me that I had to try it out. ;) ) – manatwork Oct 13 '14 at 16:16
  • 12
    Shouldn't it be "Dear C" (uppercase)? – TRiG Oct 14 '14 at 10:35
  • I miss also the interpunction characters there... – V-X Oct 14 '14 at 10:50

Python, 61 60 59

H="\nHappy Birthday to You"
print(H*3)[:60]+"Dear Python"+H
  • 1
    You can save 1 byte - H="\nHappy Birthday to You" and print(H*3)[:59]+" Dear Python"+H – Stretch Maniac Oct 13 '14 at 16:37
  • 1
    Is this python 2.7 or 3? – George Oct 13 '14 at 20:56
  • 2
    @George: Python 2.7, as it has no brackets around the print argument. – Falko Oct 13 '14 at 20:59
  • 1
    Does output from an interactive interpreter count? h="\nHappy Birthday to You";(h*3)[:60]+"Dear Python"+h – threed Oct 15 '14 at 22:54
  • 1
    You can save one more by removing the space before Dear and changing 59 to 60. – threed Oct 15 '14 at 22:55

sh, 52

H()(echo Happy Birthday ${@-to You});H;H;H Dear sh;H
  • 3
    With default value parameter expansion just 53 characters: H()(echo Happy Birthday ${@:-to You});H;H;H Dear sh;H. – manatwork Oct 13 '14 at 16:07
  • Ooh very good @manatwork! – Digital Trauma Oct 13 '14 at 16:12
  • 2
    You can omit the colon in the parameter expansion - that works if the parameter was never set, while :- also covers cases when it is set but empty – user16402 Oct 13 '14 at 19:34
  • @professorfish Nice - thanks, I didn't know that! – Digital Trauma Oct 13 '14 at 21:18
  • @DigitalTrauma A good place to look if you need to save characters is wiki.bash-hackers.org/syntax/pe - there's a list of all parameter expansion syntax – user16402 Oct 14 '14 at 7:23

ArnoldC, 228 bytes

Lets make Arnold Schwarzenegger singing...

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

output:

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

APL (48)

↑1⌽'Happy birthday '∘,¨(3/⊂'to you'),⊂'dear APL'

Shakespeare Programming Language, 3429 bytes

no one is going to be demented enough to enter a challenge with SPL, so...

My own words, a while ago. And yet, someone was demented enough to do it. Yes, yes, I know. Too much bytes. But SPL deserves to be included here, I think. And believe me, I've done a gargantuan effort to "golf" this program, which is why it's a bit repetitive and uses mostly the same words (I could always have followed DLosc's suggestion, but that would be too extreme even for me).

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]

The meaning of all this?

OK, if you're curious about how all of this is supposed to work, let me try and explain my reasoning. Firstly, the variables. They have to come from Shakesperian plays and, since tharacter count is important, we have to choose the small ones; thus, Ajax and Ford appear. They need a description after being declared (which is ignored, but still); I could've used a single letter, but heh.

Act I, Scene I

var Ajax, Ford; Ford = 0;

We bring the variables into the stage and make Ajax tell Ford that his value will be 0.

Act I, Scene II

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

OK, if the value stored in Ford is bigger than 3, the program jumps to Scene V; otherwhise, its value is incremented.

Act I, Scene III

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;

Loads and loads of lines. The idea is to fiddle with the value stored on Ford, doing loads and loads of arithmetic operations in order to get the ASCII number of the desired letters, then we tell the compiler to output the number in character form. That's how you write Happy Birthday. There's an if inside this scene: the idea is to check if this is the third phrase of the song; if it is, we jump to Scene IV; otherwise we keep on forward, to write to You. After that, we jump back to Scene II.

Act I, Scene IV

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;

The way this works is similar to the Scene above: the idea is to write Dear SPL.

Act I, Scene V

End.

Just like that.

I still haven't found any place where this can be tested, unfortunately...

Ruby, 54 bytes

I just thought "Hey, there's no Ruby answer yet", but then one appeared a few seconds before this one. Oh well...

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

Any love for PHP? 61 59 58 bytes

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

See it in action @ http://sandbox.onlinephpfunctions.com/

  • 1
    Combine the assignment to $t with its first output: $s="\nHappy Birthday";echo$t="$s to You","$t$s Dear PHP$t"; – manatwork Oct 14 '14 at 12:57
  • @manatwork excellent suggestion, thanks! – MonkeyZeus Oct 14 '14 at 13:10
  • 53
    No. There is no love for PHP. Ever. – Fake Name Oct 15 '14 at 4:22
  • Same number of bytes with short tags: <?=$t=($s="\nHappy Birthday")." to You","$t$s Dear PHP$t"?> – AmadeusDrZaius Oct 18 '14 at 19:12
  • 1
    Replace the \n with an actual line break in order to save a char. – Christoph Apr 21 '17 at 11:04

I just can't decide on just one language :/

BrainBack: 68

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

BrainBack is a mix between BrainFuck and Forth, made for a PCG challenge Mar 7, 2014

Extended BrainFuck: 79

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

EBF's birthday is Jul 16, 2010

Scheme: 96

(R5RS, Racket, R6RS REPL)

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

Scheme was born Dec, 1975 (NB: PDF)

Zozotez: 96

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

However, It feels more right doing this one in French (86):

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

Output:

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

Zozotez' birthday is Jul 19, 2011

  • 4
    +1 for "Happy birthday dear Extended Brainfuck", probably the most laborious language name here. And yet the program is a fraction of the size of the equivalent for the parent language. And for Zozotez, which does indeed sound better in French, though in general I don't much like the way the French squeeze the person's name into an identical line for this song. – Level River St Oct 13 '14 at 23:42
  • In your Zozotez answer, it should be Joyeux anniversaire à Zozotez. – Beta Decay Oct 17 '14 at 18:00
  • 2
    @BetaDecay According to my (French) wife it should be without such preposition. French Wikipedia agrees. – Sylwester Oct 17 '14 at 21:07

Deadfish (2610 2391 chars)

What's this? An output only challenge? Sound like it's a job for Deadfish!

iiisdsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiiiiiiiiooiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiioiioddddddddddddoddddodddoiiiiiiiiiiiiiiiiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddsdddddodddddodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddddsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiioiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiiiiiiiiooiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiioiioddddddddddddoddddodddoiiiiiiiiiiiiiiiiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddsdddddodddddodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddddsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiioiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiiiiiiiiooiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiioiioddddddddddddoddddodddoiiiiiiiiiiiiiiiiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiiiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioddddoiiiiiiiiiiiiiiiiioddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiiiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioddddoiiioiioiiioiiiiiiiiiiodddddddddddoddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiiiiiiiiooiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiioiioddddddddddddoddddodddoiiiiiiiiiiiiiiiiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddsdddddodddddodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddddsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiioiiiiiio

Unfortunately, because Deadfish only outputs integers, the code above outputs the ASCII representations of each character in the song.

If we use the specification that

Errors are not acknowledged: the shell simply adds a newline character!

then we can golf this down to 2391 chars:

iiisdsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiiiiiiiiooiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiioiioddddddddddddoddddodddoiiiiiiiiiiiiiiiiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddsdddddodddddodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddddsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiioiiiiiiofdddddddddddddddddddddddddddddddddddddddddddddoiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiiiiiiiiooiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiioiioddddddddddddoddddodddoiiiiiiiiiiiiiiiiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddsdddddodddddodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddddsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiioiiiiiiofdddddddddddddddddddddddddddddddddddddddddddddoiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiiiiiiiiooiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiioiioddddddddddddoddddodddoiiiiiiiiiiiiiiiiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiiiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioddddoiiiiiiiiiiiiiiiiioddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiiiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioddddoiiioiioiiioiiiiiiiiiiodddddddddddofddddddddddddddddddddddddddddddddoiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiiiiiiiiooiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoddddddddddddddddddddddddsiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiiioiioddddddddddddoddddodddoiiiiiiiiiiiiiiiiiiiiiiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddsdddddodddddodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddddsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiioiiiiiio 

Note: Deadfish isn't actually my favourite language, but I couldn't resist :P. Also golfing in Deadfish is a fun puzzle on its own.

  • 19
    For certain values of "fun". – Charles Wood Oct 15 '14 at 20:12

JS, 83 bytes

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

or 79 bytes by @Ingo Bürk

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

or 71 bytes by @kapep

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

or run on the console this page (42 bytes)

eval($("#answer-39759 code:first").text())
  • 4
    Also, this is shorter: h='Happy Birthday ',t='to You\n';console.log(h+t,h+t,h+'Dear Javascript\n',h+t) (you can still use prompt to save even more) – Ingo Bürk Oct 13 '14 at 13:50
  • 10
    LOL at the last code piece .. :D – Optimizer Oct 13 '14 at 14:00
  • 1
    76: t='to you\n';console.log(h='Happy birthday',t+h,t+h,'dear JavaScript\n'+h,t) – NinjaBearMonkey Oct 13 '14 at 14:21
  • 1
    71: console.log(a=(b="Happy Birthday ")+"to You\n",a,b+"Dear Javascript\n",a) – kapex Oct 14 '14 at 2:13
  • 3
    alert instead console.log, needs 2 more brackets but shorter: alert((t=(h="Happy Birthday ")+'to You\n')+t+h+'dear EcmaScript\n'+t) 69 – edc65 Oct 14 '14 at 15:32

R: 70 bytes

Takes advantage of paste and vector recycling.

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')) – germcd Oct 13 '14 at 21:01
  • @germcd That doesn't quite work, since cat adds spaces between the strings. So you end up with a space at the beginning of each line except the first. – bdzimmer Oct 14 '14 at 3:34
  • write(x,"") -> write(paste(rep("Happy Birthday",4),c(rep("to You",2),"Dear R")),"") 68 bytes. Here is my original solution with 73 p=paste;write(c(i<-p(h<-"Happy Birthday","to You"),i,p(h,"Dear R"),i),"") Vector recycling beats me again. – Vlo Oct 16 '14 at 14:58

GNU dc, 51

[Happy Birthday to You]d[Happy Birthday Dear dc]rdf
  • 3
    I also tried with dc, but even the almost raw version is shorter: [Happy Birthday To You]d[Happy Birthday Dear dc]rdf 51 characters. – manatwork Oct 13 '14 at 16:11
  • On a roll today @manatwork :) – Digital Trauma Oct 13 '14 at 16:14
  • 3
    I learned of the existence of dc today because of this post and it's excellent. – Caleb Paul Oct 19 '14 at 13:40

Perl - 58

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

Run with:

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

Just for fun:

perl -E'for(<HappyBirthday{0,1,2,3}>){s/B/ B/;s/2/ Dear Perl\n/;print s/\d/ To You\n/r}'
  • 6
    How about say"Happy Birthday $_"for("to You","Dear Perl")[0,0,1,0] ? – core1024 Oct 14 '14 at 20:47
  • @core1024 I didn't know you could do that with arrays, that's awesome. Feel free to post as your own answer! – chilemagic Oct 20 '14 at 23:54

T-SQL: 89

Using STUFF to remove unwanted parts of the string

SELECT STUFF('Happy Birthday to You  Dear SQL',N,8,'')FROM(VALUES(24),(24),(15),(24))S(N)
  • This one is nice! – TLama Oct 20 '14 at 23:16
  • This is a brilliant SQL solution and a very nice trick! – BradC Jan 11 at 15:50

Ruby, 56

x="Happy Birthday To You
"*4
x[59,6]="Dear Ruby"
puts x
  • Can't you inline things ? – Optimizer Oct 13 '14 at 14:04
  • 2
    A method ending in = always returns the result of the expression after the equals sign. If I inlined this, it'd only print "Dear Ruby" (String#[]= is a method). – britishtea Oct 13 '14 at 14:07
  • >Newlines in strings. Okay, now i'm completely convinced that ruby is just voodoo magic and as a peasant I should stick to python instead. – sagiksp Apr 19 '17 at 5:35

Marbelous, 151

Prints Happy Birthday every time hb is called, with either to you or Dear Marbelous appended, based on whether the input is 0 or 1. The passed marble in hb will not be outputted, as it will get stuck in the synchroniser &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

Below is the board hb, with hex converted to ascii text: enter image description here

PowerShell - 69 64 59

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

and 91

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

and 108

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

Python 507 bytes

print """
H  a     p     py-  Bir  t   h    day  -to-Y ou=  Happy -  B irt       h     d   a y
-  t    o -    Y  o u  =  H a     p  p   y   -  B   i   r  t h  d     a y     - D  e
ar-P   ython   =Ha  ppy    -      Bir    t   hda    y   -to- Y   o   uHapp     y   -
B  i  r     t  h    d      a      y  -   t   o -    Y   o  u =  H   a     p    p
y  - B       i r    t      h      day  -to-Y o  u   =   H  a ppy   -       B   i   r
""".replace("\n","").replace(" ","").replace("-"," ").replace("=","\n")[:92]

Not winning any prizes ... but if you look at it carefully, there is some ASCII art:

#  #     #     ###  ###  #   #    ###  ##### ###  ##### #  # ###       #     #   # #
#  #    # #    #  # #  #  # #     #  #   #   #  #   #   #  # #  #     # #     # #  #
####   #####   ###  ###    #      ###    #   ###    #   #### #   #   #####     #   #
#  #  #     #  #    #      #      #  #   #   # #    #   #  # #  #   #     #    #
#  # #       # #    #      #      ###  ##### #  #   #   #  # ###   #       #   #   #
  • This is not a serious contender. – Esolanging Fruit Jun 4 '17 at 6:54
  • 2
    @Challenger5 Yes, "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." – Alex Jun 4 '17 at 18:09

CJam, 46 bytes

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

Try it here.

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";

This leaves the following array on the stack:

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

Whose contents are automatically printed back-to-back at the end of the program.

Alternatively, with a for-loop and the same character count:

4{"Happy Birthday "I2="Dear CJam""to You"?N}fI
  • 5
    Liar!! your favorite language is Ruby/Mathematica :P – Optimizer Oct 13 '14 at 11:41
  • 1
    @Optimizer Certainly not Ruby, maybe Mathematica, but I'm not even sure about that. For "real" programming I'd probably always choose C/C++/C#. (I'm also pretty sure, that yours is JS :P.) – Martin Ender Oct 13 '14 at 11:44
  • 5
    you got me :P :D – Optimizer Oct 13 '14 at 11:48

Haskell: 75

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

Code output in ideone

Haskell one liner: 79

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

You can try the one liner online here: http://tryhaskell.org/

  • 1
    A one liner that shaves off one character: mapM_(print.("Happy Birthday "++))["to You","to You","dear Haskell","to You"] – Alex Reinking Oct 18 '14 at 2:42
  • list comprehensions are soooo loooonnnnggggg – Alex Reinking Oct 18 '14 at 2:45
  • 2
    also, it should technically be putStrLn to conform to the spec (you get double quotes with print) – Alex Reinking Oct 18 '14 at 2:45
  • 2
    The _ is not needed because the return value of main is thrown away - you only see it in GHCi – proud haskeller Oct 18 '14 at 10:43

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
    Qapla'! +1 for using Var'aQ of all languages! – WallyWest Oct 15 '14 at 4:37

GolfScript: 54 characters

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

Sample run:

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
  • I just noticed it. (Little side effect of trying to write that GolfScript code for about 5~6 hours.) Thanks, @MartinBüttner. – manatwork Oct 13 '14 at 17:08
  • 1
    Happy Birthday Dear CodeGolf? – Dennis Oct 14 '14 at 2:09
  • Grr. I was tired not only when wrote it, but also when fixed it. Thanks @Dennis. – manatwork Oct 14 '14 at 8:06

C# (75) (73)

Using System.Diagnostics for the purpose of Debug.Print

Upgrade to @Abbas' code

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

Upgrade to @Tyress' code (83) (76)

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

Output:

Happy Birthday To You
Happy Birthday To You
Happy Birthday Dear C#
Happy Birthday To You
  • 2
    You can save a couple characters using String.Format and the ternary operator. You can also make this look much less like a C# program and use i++<3 ;p – FryAmTheEggman Oct 15 '14 at 16:35

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.