131
\$\begingroup\$

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.

Leaderboard

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

/* Configuration */

var QUESTION_ID = 39752; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 48934; // This should be the user ID of the challenge author.

/* App */

var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;

function answersUrl(index) {
  return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

function commentUrl(index, answers) {
  return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}

function getAnswers() {
  jQuery.ajax({
    url: answersUrl(answer_page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      answers_hash = [];
      answer_ids = [];
      data.items.forEach(function(a) {
        a.comments = [];
        var id = +a.share_link.match(/\d+/);
        answer_ids.push(id);
        answers_hash[id] = a;
      });
      if (!data.has_more) more_answers = false;
      comment_page = 1;
      getComments();
    }
  });
}

function getComments() {
  jQuery.ajax({
    url: commentUrl(comment_page++, answer_ids),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      data.items.forEach(function(c) {
        if (c.owner.user_id === OVERRIDE_USER)
          answers_hash[c.post_id].comments.push(c);
      });
      if (data.has_more) getComments();
      else if (more_answers) getAnswers();
      else process();
    }
  });  
}

getAnswers();

var SCORE_REG = /<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

var OVERRIDE_REG = /^Override\s*header:\s*/i;

function getAuthorName(a) {
  return a.owner.display_name;
}

function process() {
  var valid = [];
  
  answers.forEach(function(a) {
    var body = a.body;
    a.comments.forEach(function(c) {
      if(OVERRIDE_REG.test(c.body))
        body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
    });
    
    var match = body.match(SCORE_REG);
    if (match)
      valid.push({
        user: getAuthorName(a),
        size: +match[2],
        language: match[1],
        link: a.share_link,
      });
    
  });
  
  valid.sort(function (a, b) {
    var aB = a.size,
        bB = b.size;
    return aB - bB
  });

  var languages = {};
  var place = 1;
  var lastSize = null;
  var lastPlace = 1;
  valid.forEach(function (a) {
    if (a.size != lastSize)
      lastPlace = place;
    lastSize = a.size;
    ++place;
    
    var answer = jQuery("#answer-template").html();
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
                   .replace("{{NAME}}", a.user)
                   .replace("{{LANGUAGE}}", a.language)
                   .replace("{{SIZE}}", a.size)
                   .replace("{{LINK}}", a.link);
    answer = jQuery(answer);
    jQuery("#answers").append(answer);

    var lang = a.language;
    if (/<a/.test(lang)) lang = jQuery(lang).text();
    
    languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link};
  });

  var langs = [];
  for (var lang in languages)
    if (languages.hasOwnProperty(lang))
      langs.push(languages[lang]);

  langs.sort(function (a, b) {
    if (a.lang > b.lang) return 1;
    if (a.lang < b.lang) return -1;
    return 0;
  });

  for (var i = 0; i < langs.length; ++i)
  {
    var language = jQuery("#language-template").html();
    var lang = langs[i];
    language = language.replace("{{LANGUAGE}}", lang.lang)
                       .replace("{{NAME}}", lang.user)
                       .replace("{{SIZE}}", lang.size)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }

}
body { text-align: left !important}

#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}

#language-list {
  padding: 10px;
  width: 290px;
  float: left;
}

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">
<div id="answer-list">
  <h2>Leaderboard</h2>
  <table class="answer-list">
    <thead>
      <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>
    </thead>
    <tbody id="answers">

    </tbody>
  </table>
</div>
<div id="language-list">
  <h2>Winners by Language</h2>
  <table class="language-list">
    <thead>
      <tr><td>Language</td><td>User</td><td>Score</td></tr>
    </thead>
    <tbody id="languages">

    </tbody>
  </table>
</div>
<table style="display: none">
  <tbody id="answer-template">
    <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>
<table style="display: none">
  <tbody id="language-template">
    <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>

\$\endgroup\$
16
  • 5
    \$\begingroup\$ 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? \$\endgroup\$
    – MonkeyZeus
    Commented Oct 13, 2014 at 18:49
  • 16
    \$\begingroup\$ Why all the upvotes for this despite all the downvotes for the Bonbon song? This is just as boring a challenge. \$\endgroup\$
    – xnor
    Commented Oct 14, 2014 at 7:15
  • 10
    \$\begingroup\$ I should probably mention that the song is copyrighted and distributing these programs may cause a DMCA \$\endgroup\$ Commented Oct 14, 2014 at 14:38
  • 13
    \$\begingroup\$ guys! Happy Birthday song is now in public domain!! \$\endgroup\$
    – Optimizer
    Commented Sep 23, 2015 at 10:01
  • 5
    \$\begingroup\$ At least one of the answers prints a leading newline. Is that allowed? \$\endgroup\$
    – Dennis
    Commented Jun 19, 2016 at 21:32

211 Answers 211

1
2 3 4 5
8
121
\$\begingroup\$

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
\$\endgroup\$
4
  • 17
    \$\begingroup\$ I just knew there'd be a LOLCODE answer to this. BTW, kan u wryt n lwrcase insyd t kwotez? KTHXBYE. \$\endgroup\$ Commented Oct 15, 2014 at 18:38
  • 2
    \$\begingroup\$ 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! \$\endgroup\$ Commented Oct 16, 2014 at 20:30
  • 4
    \$\begingroup\$ This answer has given me an urge to download LOCODE and actually learn it properly. \$\endgroup\$
    – Pharap
    Commented Oct 18, 2014 at 5:53
  • 2
    \$\begingroup\$ This is great!! \$\endgroup\$
    – AStopher
    Commented Oct 20, 2014 at 15:35
92
\$\begingroup\$

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.

\$\endgroup\$
5
  • 17
    \$\begingroup\$ I can't see a barcode button on my keyboard! How can I test this? \$\endgroup\$
    – matsjoyce
    Commented Oct 20, 2014 at 15:49
  • 18
    \$\begingroup\$ I love that there's a 10 in the barcode (bottom right corner), seeing that BarcodeRecognize was introduced in Mathematica 10. ^^ \$\endgroup\$ Commented Oct 23, 2014 at 10:54
  • \$\begingroup\$ Yes! I hadn't noticed that. \$\endgroup\$
    – DavidC
    Commented Oct 23, 2014 at 12:49
  • 12
    \$\begingroup\$ 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. \$\endgroup\$
    – Timwi
    Commented Jan 8, 2016 at 17:41
  • \$\begingroup\$ @Timwi, The code replaces the comma with a new line code". \$\endgroup\$
    – DavidC
    Commented Jun 28, 2020 at 17:27
60
\$\begingroup\$

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.

\$\endgroup\$
9
  • 7
    \$\begingroup\$ 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. \$\endgroup\$ Commented Oct 14, 2014 at 18:44
  • 5
    \$\begingroup\$ 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. \$\endgroup\$ Commented Oct 14, 2014 at 19:58
  • 2
    \$\begingroup\$ +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. \$\endgroup\$
    – Nacht
    Commented Oct 15, 2014 at 22:42
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ Commented Oct 18, 2014 at 22:08
  • 2
    \$\begingroup\$ There are lowercase letters on your calculator, but typing them in is nontrivial and they take 2 bytes each. \$\endgroup\$
    – lirtosiast
    Commented Jun 7, 2015 at 0:22
49
\$\begingroup\$

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)

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

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

C, 73 bytes

main(c){for(;c-5;)printf("Happy Birthday %s\n",++c-4?"To You":"Dear C");}
\$\endgroup\$
6
  • \$\begingroup\$ 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”.) \$\endgroup\$
    – manatwork
    Commented Oct 13, 2014 at 16:02
  • \$\begingroup\$ constant fixed, variable changed. Any idea to shorten the code? \$\endgroup\$
    – V-X
    Commented Oct 13, 2014 at 16:08
  • \$\begingroup\$ 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. ;) ) \$\endgroup\$
    – manatwork
    Commented Oct 13, 2014 at 16:16
  • 13
    \$\begingroup\$ Shouldn't it be "Dear C" (uppercase)? \$\endgroup\$
    – TRiG
    Commented Oct 14, 2014 at 10:35
  • \$\begingroup\$ I miss also the interpunction characters there... \$\endgroup\$
    – V-X
    Commented Oct 14, 2014 at 10:50
29
\$\begingroup\$

Python, 61 60 59

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

sh, 52

H()(echo Happy Birthday ${@-to You});H;H;H Dear sh;H
\$\endgroup\$
5
  • 3
    \$\begingroup\$ With default value parameter expansion just 53 characters: H()(echo Happy Birthday ${@:-to You});H;H;H Dear sh;H. \$\endgroup\$
    – manatwork
    Commented Oct 13, 2014 at 16:07
  • \$\begingroup\$ Ooh very good @manatwork! \$\endgroup\$ Commented Oct 13, 2014 at 16:12
  • 2
    \$\begingroup\$ 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 \$\endgroup\$
    – user16402
    Commented Oct 13, 2014 at 19:34
  • \$\begingroup\$ @professorfish Nice - thanks, I didn't know that! \$\endgroup\$ Commented Oct 13, 2014 at 21:18
  • \$\begingroup\$ @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 \$\endgroup\$
    – user16402
    Commented Oct 14, 2014 at 7:23
22
\$\begingroup\$

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...

\$\endgroup\$
1
21
\$\begingroup\$

APL (48)

↑1⌽'Happy birthday '∘,¨(3/⊂'to you'),⊂'dear APL'
\$\endgroup\$
3
21
\$\begingroup\$

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
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Invalid input '\', expected '"' (line 2, pos 40) \$\endgroup\$
    – r3mainer
    Commented Oct 15, 2014 at 21:58
  • \$\begingroup\$ @squeamishossifrage lol, fixed. \$\endgroup\$
    – Wasi
    Commented Oct 16, 2014 at 5:34
  • 17
    \$\begingroup\$ Perhaps you can add an Ahnold lisp! Hahpy Birfday reduces character count by 4. \$\endgroup\$
    – Compass
    Commented Oct 16, 2014 at 19:27
16
\$\begingroup\$

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
\$\endgroup\$
0
16
\$\begingroup\$

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

\$\endgroup\$
3
  • 5
    \$\begingroup\$ +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. \$\endgroup\$ Commented Oct 13, 2014 at 23:42
  • \$\begingroup\$ In your Zozotez answer, it should be Joyeux anniversaire à Zozotez. \$\endgroup\$
    – Beta Decay
    Commented Oct 17, 2014 at 18:00
  • 2
    \$\begingroup\$ @BetaDecay According to my (French) wife it should be without such preposition. French Wikipedia agrees. \$\endgroup\$
    – Sylwester
    Commented Oct 17, 2014 at 21:07
16
\$\begingroup\$

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/

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

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.

\$\endgroup\$
1
  • 21
    \$\begingroup\$ For certain values of "fun". \$\endgroup\$ Commented Oct 15, 2014 at 20:12
13
\$\begingroup\$

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())
\$\endgroup\$
9
  • 4
    \$\begingroup\$ 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) \$\endgroup\$
    – Ingo Bürk
    Commented Oct 13, 2014 at 13:50
  • 11
    \$\begingroup\$ LOL at the last code piece .. :D \$\endgroup\$
    – Optimizer
    Commented Oct 13, 2014 at 14:00
  • 1
    \$\begingroup\$ 76: t='to you\n';console.log(h='Happy birthday',t+h,t+h,'dear JavaScript\n'+h,t) \$\endgroup\$ Commented Oct 13, 2014 at 14:21
  • 1
    \$\begingroup\$ 71: console.log(a=(b="Happy Birthday ")+"to You\n",a,b+"Dear Javascript\n",a) \$\endgroup\$
    – kapex
    Commented Oct 14, 2014 at 2:13
  • 3
    \$\begingroup\$ 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 \$\endgroup\$
    – edc65
    Commented Oct 14, 2014 at 15:32
12
\$\begingroup\$

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:

#  #     #     ###  ###  #   #    ###  ##### ###  ##### #  # ###       #     #   # #
#  #    # #    #  # #  #  # #     #  #   #   #  #   #   #  # #  #     # #     # #  #
####   #####   ###  ###    #      ###    #   ###    #   #### #   #   #####     #   #
#  #  #     #  #    #      #      #  #   #   # #    #   #  # #  #   #     #    #
#  # #       # #    #      #      ###  ##### #  #   #   #  # ###   #       #   #   #
\$\endgroup\$
2
  • \$\begingroup\$ This is not a serious contender. \$\endgroup\$ Commented Jun 4, 2017 at 6:54
  • 6
    \$\begingroup\$ @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." \$\endgroup\$
    – Alex
    Commented Jun 4, 2017 at 18:09
11
\$\begingroup\$

R: 70 bytes

Takes advantage of paste and vector recycling.

writeLines(paste(rep("Happy Birthday",4),c(rep("to You",2),"Dear R")))
\$\endgroup\$
4
  • \$\begingroup\$ cat(paste(rep("Happy Birthday",4),c(rep("to You",2),"Dear R"),'\n')) \$\endgroup\$
    – germcd
    Commented Oct 13, 2014 at 21:01
  • \$\begingroup\$ @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. \$\endgroup\$
    – bdzimmer
    Commented Oct 14, 2014 at 3:34
  • \$\begingroup\$ 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. \$\endgroup\$
    – Vlo
    Commented Oct 16, 2014 at 14:58
  • \$\begingroup\$ Reduced to 66 bytes `~`=rep;write(paste("Happy Birthday"~4,c("to You"~2,"Dear R")),"") tio.run/##K/r/… \$\endgroup\$ Commented Feb 23, 2019 at 22:04
11
\$\begingroup\$

T-SQL, 89 87 bytes

Edit: Probably shouldn't be dredging these old things up, but I just noticed an obvious change to this to reclaim a couple of bytes.

Using STUFF to remove unwanted parts of the string, the starting index is provided by the values in the FROM clause multiplied by 3

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

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]
p[Y1:Y5,Z1,AA2,Z3,AA4,Z5,AC1:AE1,AD2:AD4,AC5:AE5,AG1:AG5,AH1,AI2,AH3,AI4:AI5,AK1:AM1,AL2:Al5,AO1:AO5,AP3,AQ1:AQ5,AS1:AS5,AT1,AU2:AU4,AT5,AX1,AW2:AW5,AY2:AY5,AX3,BA1:BA2,BB3:BB5,BC1:BC2]
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

Output

enter image description here

\$\endgroup\$
1
  • 1
    \$\begingroup\$ This is a nice answer, +1 \$\endgroup\$ Commented Sep 23, 2017 at 20:32
9
\$\begingroup\$

GNU dc, 51

[Happy Birthday to You]d[Happy Birthday Dear dc]rdf
\$\endgroup\$
3
  • 3
    \$\begingroup\$ 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. \$\endgroup\$
    – manatwork
    Commented Oct 13, 2014 at 16:11
  • \$\begingroup\$ On a roll today @manatwork :) \$\endgroup\$ Commented Oct 13, 2014 at 16:14
  • 4
    \$\begingroup\$ I learned of the existence of dc today because of this post and it's excellent. \$\endgroup\$
    – Caleb Paul
    Commented Oct 19, 2014 at 13:40
9
\$\begingroup\$

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}'
\$\endgroup\$
2
  • 6
    \$\begingroup\$ How about say"Happy Birthday $_"for("to You","Dear Perl")[0,0,1,0] ? \$\endgroup\$
    – core1024
    Commented Oct 14, 2014 at 20:47
  • \$\begingroup\$ @core1024 I didn't know you could do that with arrays, that's awesome. Feel free to post as your own answer! \$\endgroup\$
    – hmatt1
    Commented Oct 20, 2014 at 23:54
7
\$\begingroup\$

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
\$\endgroup\$
1
  • \$\begingroup\$ "Dear $ShellId". That made me smile. \$\endgroup\$ Commented Mar 17 at 0:30
6
\$\begingroup\$

Ruby, 56

x="Happy Birthday To You
"*4
x[59,6]="Dear Ruby"
puts x
\$\endgroup\$
3
  • \$\begingroup\$ Can't you inline things ? \$\endgroup\$
    – Optimizer
    Commented Oct 13, 2014 at 14:04
  • 2
    \$\begingroup\$ 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). \$\endgroup\$
    – britishtea
    Commented Oct 13, 2014 at 14:07
  • 2
    \$\begingroup\$ >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. \$\endgroup\$
    – sagiksp
    Commented Apr 19, 2017 at 5:35
5
\$\begingroup\$

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
\$\endgroup\$
3
  • 5
    \$\begingroup\$ Liar!! your favorite language is Ruby/Mathematica :P \$\endgroup\$
    – Optimizer
    Commented Oct 13, 2014 at 11:41
  • 1
    \$\begingroup\$ @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.) \$\endgroup\$ Commented Oct 13, 2014 at 11:44
  • 5
    \$\begingroup\$ you got me :P :D \$\endgroup\$
    – Optimizer
    Commented Oct 13, 2014 at 11:48
5
\$\begingroup\$

Var'aQ - 121

"Happy Birthday " ~ a cher "to you\n" tlheghrar ~ b cher b tlheghrar a "dear Var'aQ" tlheghrar tlheghrar b tlheghrar cha'
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Qapla'! +1 for using Var'aQ of all languages! \$\endgroup\$ Commented Oct 15, 2014 at 4:37
  • \$\begingroup\$ Would be better if you translated the song to Klingon too :) \$\endgroup\$
    – matt
    Commented Jun 22, 2020 at 18:04
5
\$\begingroup\$

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

T-SQL (MS compliant): 75

print stuff(replicate('Happy Birthday to You '+char(10),4),62,6,'Dear SQL')
\$\endgroup\$
2
  • \$\begingroup\$ Nice one ... wish I had thought of that:) \$\endgroup\$
    – MickyT
    Commented Oct 20, 2014 at 23:46
  • \$\begingroup\$ Great idea! Save 9 more bytes by replacing +char(10) with a line break inside the quote, just make the return part of the string. \$\endgroup\$
    – BradC
    Commented Jan 11, 2018 at 15:56
5
\$\begingroup\$

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

\$\endgroup\$
5
\$\begingroup\$

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
\$\endgroup\$
1
  • 2
    \$\begingroup\$ 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 \$\endgroup\$ Commented Oct 15, 2014 at 16:35
1
2 3 4 5
8

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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