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.


    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.


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


    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 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 "" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;

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

    function getAnswers() {
    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+/);
    answers_hash[id] = a;
    if (!data.has_more) more_answers = false;
    comment_page = 1;

    function getComments() {
    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)
    if (data.has_more) getComments();
    else if (more_answers) getAnswers();
    else process();


    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) {
    body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';

    var match = body.match(SCORE_REG);
    if (match)
    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;

    var answer = jQuery("#answer-template").html();
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
    .replace("{{NAME}}", a.user)
    .replace("{{LANGUAGE}}", a.language)
    .replace("{{SIZE}}", a.size)
    answer = jQuery(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:};

    var langs = [];
    for (var lang in languages)
    if (languages.hasOwnProperty(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)
    language = jQuery(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=""></script>
    <link rel="stylesheet" type="text/css" href="//">
    <div id="answer-list">
    <table class="answer-list">
    <tbody id="answers">

    <div id="language-list">
    <h2>Winners by Language</h2>
    <table class="language-list">
    <tbody id="languages">

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

    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 Sorry, but taking length differences into account is intended. Since you don't have to be the shortest to gain popularity points, it shouldn't matter too much. There is also a tendency that programs written in a programming language that has a longer name, need less characters to implement the same functionality.

    I am no cross-programming guru but if 2 languages happen to achieve the goal in the same amount of logic bytes then it's kind of like getting penalized for getting your coffee from a "coffee shop" compared to a "café". Disclaimer: I am not a coffee connoisseur.

    Why all the upvotes for this despite all the downvotes for the Bonbon song? This is just as boring a challenge.

    @DavidFrank "Sorry, but taking length differences into account is intended. Since you don't have to be the shortest to gain popularity points, it shouldn't matter too much." Um, it's code golf, not a popularity contest. Votes are irrelevant and the shortest program wins. So you *are* being penalized for, e.g., writing in Microsoft Visual C++ rather than vanilla C (though, in that case, it's probably deserved).

    I should probably mention that the song is copyrighted and distributing these programs may cause a DMCA

    @DavidRicherby I'm sorry that the rules are not to your liking. I think this is more or less widespread practise to include the programming language name in the solution. Votes are not irrelevant (you gain xp by votes), though you might not win the contest. However, you have a free choice in your favourite programming language. In this contest not only solutions but also programming languages compete.

    @xnor Not sure, but people seem to like it any time you make them put their language name in the output.

    With the sheer number of answers, this seems to be more of a pop-con than code golf... How are you going to be able to find the shortest answer?

    @BetaDecay. Sorry i don't know the full etiquette yet. Comment deleted.

    @xnor Because the Bonbon song never made it to the HNQ.

    At least one of the answers prints a *leading* newline. Is that allowed?

    Hmm.. if anyone posts more than one answer to this question, they must be lying. It says to use your *favorite* programming language.

    It's 6 months to and from its birthday. Singing such is quite strange

    "Tasks that depend on a language's name are a form of disadvantaging some languages by arbitrary criteria." -- quote Martin Ender from this closed challenge.

  • Optimizer

    Optimizer Correct answer

    7 years ago

    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?

    Yeah, a-f are 10-15.

License under CC-BY-SA with attribution

Content dated before 7/24/2021 11:53 AM