119
22
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>
12guys! Happy Birthday song is now in public domain!! – Optimizer – 2015-09-23T10:01:41.610
4At least one of the answers prints a leading newline. Is that allowed? – Dennis – 2016-06-19T21:32:31.070
Possible duplicate of We're no strangers to code golf, you know the rules, and so do I
– Blue – 2016-07-03T13:24:48.943Hmm.. if anyone posts more than one answer to this question, they must be lying. It says to use your favorite programming language. – 12Me21 – 2018-03-10T21:22:48.723
It's 6 months to and from its birthday. Singing such is quite strange – l4m2 – 2018-03-12T01:16:52.400
"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.
– user202729 – 2018-06-26T08:26:14.7832Can 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 – 2014-10-13T18:49:37.790
1@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. – David Frank – 2014-10-13T19:02:38.213
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. – MonkeyZeus – 2014-10-13T19:51:12.507
14
Why all the upvotes for this despite all the downvotes for the Bonbon song? This is just as boring a challenge.
– xnor – 2014-10-14T07:15:27.6171@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). – David Richerby – 2014-10-14T12:40:32.133
10
I should probably mention that the song is copyrighted and distributing these programs may cause a DMCA
– ratchet freak – 2014-10-14T14:38:53.2301@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. – David Frank – 2014-10-14T16:07:28.417
@xnor Not sure, but people seem to like it any time you make them put their language name in the output.
– Calvin's Hobbies – 2014-10-14T16:34:52.4031With 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? – Beta Decay – 2014-10-17T17:56:27.763
@BetaDecay. Sorry i don't know the full etiquette yet. Comment deleted. – Hoki – 2014-10-18T12:25:46.353
1@xnor Because the Bonbon song never made it to the HNQ. – Martin Ender – 2014-10-23T10:55:21.940