• Coding
  • [Exercise] Happy Birthday golf

Here's my best one so far at 97 characters of Python code:
print "\n".join(map("".join,zip(['Happy Birthday ']*4,['to you,']*2+['dear name!']+['to you.'])))
I think I can go even lower by avoiding "to you" be repeated twice.

@mesa177: I wouldn't have posted the exercise if I didn't know how to beat your solution...

@ILIA_93: Good catch for the colored text, but in the interest of sanity, we can ignore the coloration of the text (which, quite frankly, is a problem with the formatting software of this forum and not at all intentional).
Put the text to print in a separated file. Let " f " be this file.

Using perl 48 chars:
open(FILE,"f");while(<FILE>){print$_;}closeFILE; 
Using Bash.. well 4 chars:
 cat f 

Cheating :) ?
Here's my shortest attempt in Ruby at 72 characters.
s="Happy Birthday to you,\n";puts s+s+s[0,15]+"dear name!\n"+s[0,21]+'.'
And some other ideas that are longer.
s="Happy Birthday to you,";[s,s,s[0,15]+"dear name!",s.chop+'.'].each{|l|puts l}
s="Happy Birthday to you,";puts [s,s,s[0,15]+"dear name!",s.chop+'.'].join("\n")
s="Happy Birthday to you,\n";puts s+s+s[0,15]+"dear name!\n"+s.chop.chop+'.'
s="Happy Birthday to you,\n";puts s+s+s[0,15]+"dear name!\n"+s.sub(',','.')
Fun stuff!
C++
#include <iostream>,<string>
using namespace std;int main(){string x="Happy Birthday",z=" dear name!",y=" to you";for(int i=0;i<2;++i)cout<<x+y+','<<endl;cout<<x+z<<endl<<x+y+'.';}
Didn't spend much on it and it kind of shows, 181 (or 179, if you disregard the obligatory new line) characters.
Print@Uncompress@"1:eJxTTMoPCs5iYGDwSCwoqFRwyiwqyUhJrFQoyVeozC/ViTEwNCJFJiU1sUghLzE3VRGnTj0AnLYm2g=="
Very close to zef's solution.

Javascript / 92 characters:
h="Happy Birthday to you,\n";console.log(h+h+h.slice(0,15)+"dear name!\n"+h.slice(0,21)+'.')
There's always this too:
s="Happy Birthday to you";print"%s,\n%s,\n%s dear name!\n%s."%(s,s,s,s)
php:
echo gzinflate(base64_decode("80gsKKhUcMosKslISaxUKMlXqMwv1eHyIEo4JTWxSCEvMTdVEbsGPS4A"));
@arithma nice simple and clean solution
@arithma your solution is incorrect.
%s dear name!
Output:
Happy Birthday to you dear name!
Should be:
s="Happy Birthday to you";print"%s,\n%s,\n%s dear name!\n%s."%(s,s,s[:14],s)
@m0ei: Damn that :D, good find.
Making up for my last hickup (70 chars):
s='Happy Birthday to you,\n'*4;print s[:61]+"dear name!"+s[68:90]+'.'
2 months later
@Arithma:

You can shorten that by one more character. By moving the newlines around and using one fewer character in array indices:
s='\nHappy Birthday to you,'*4;print s[1:62]+"dear name!"+s[:22]+'.'
4 days later
a='Happy Birtday'
b='to you'
print(a,b,',\n',a,b,',\n',a,'dear name!\n',a,b,'.')
81 char python
6 days later
a="happy birthday"
b=" to you,\n"
print a+b+a+b+a+" dear name!\n"+a+b[:7]+"."
69 characters so far.
a='to you,';print"Happy Birthday %s\n"*4%(a,a,'dear name!','to you.')
m0ei wrote69 characters so far.
a='to you,';print"Happy Birthday %s\n"*4%(a,a,'dear name!','to you.')
Nice, I was thinking of similar stuff but i could not get the *4 to work...
@raja: Your answer inserts an extra newline at the beginning. ---Edit My bad it doesn't.
@m0ei: Your answer inserts an extra newline at the end.
arithma wrote@raja: Your answer inserts an extra newline at the beginning. ---Edit My bad it doesn't.
@m0ei: Your answer inserts an extra newline at the end.
What if it does? The problem was to print those lines as seen and it was accomplished am I missing something?

It could look something like this
a='to you,\n';print"Happy Birthday %s"*4%(a,a,'dear name!\n','to you.')
NuclearVision wrote What if it does? The problem was to print those lines as seen and it was accomplished am I missing something?
>>> expected = 'something'
>>> got = 'something\n'
>>> assert expected == got
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError
NuclearVision wrote
arithma wrote@raja: Your answer inserts an extra newline at the beginning. ---Edit My bad it doesn't.
@m0ei: Your answer inserts an extra newline at the end.
What if it does? The problem was to print those lines as seen and it was accomplished am I missing something?

It could look something like this
a='to you,\n';print"Happy Birthday %s"*4%(a,a,'dear name!\n','to you.')
Exactly. Now it's 72 characters. This game is about characters. Anyway, who cares, we're just making the game harder for each other for fun.