| Bytes | Lang | Time | Link |
|---|---|---|---|
| 742 | Swift 6 | 250723T225954Z | macOSist |
| 866 | C# In Linqpad | 141128T155346Z | tsavinho |
| nan | 141125T192537Z | Rodolfo | |
| 665 | Javascript | 141127T030229Z | soktinpk |
| 519 | CJam | 141125T143434Z | Martin E |
| 748 | Erlang | 141125T223825Z | Paul Guy |
| 667 | Python 2 | 141125T161041Z | Sp3000 |
Swift 6, 742 bytes
import Foundation
let c=Calendar.current,d={c.dateComponents}()([.day],{c.nextDate}()(.now,.init(month:12,day:24),.nextTime,.first,.backward)!,.now).day!-1,h=" Christmas",w=" I wish it could be\(h) every day\n"
print(d>12 ?"Well\(w)When the kids start singing and the band begins to play\nOh\(w)So let the bells ring out for\(h)":"On the \("first~second~third~four~fif~six~seven~eigh~nin~ten~eleven~twelf".split{$0>"}"}[d]+(d>2 ?"th":"")) day of\(h)\nmy true love sent to me:\n\(d<1 ?"":zip(0...,"Drummers Drumm~Pipers Pip~Lords a Leap~Ladies Danc~Maids a Milk~Swans a Swimm~Geese a Lay~Golden Ring~Calling Bird~French Hen~Turtle Dove".split{$0>"}"}).suffix(d).flatMap{"\(12-$0) \($1)\($0>6 ?"s":"ing")\n"}+"and ")a Partridge in a Pear Tree")
My longest Swift answer yet... Try it on SwiftFiddle!
C# In Linqpad - 866 bytes
Well, at least it beat Java ;) Leap years are handled inside the code.
Unformated:
void Main(){var w=DateTime.Now;int y=w.Year%4,d=w.DayOfYear,c=0,p=0;string t="Well Z\nWhen the kids start singing and the band begins to play\nOh Z\nSo let the bells ring out for X".Replace("Z","I wish it could be X every day").Replace("X","Christmas"),o="On the ",x=" day of Christmas\nmy true love sent to me:\n";string[]z={"first","second","third","forth","fifth","sixth","seventh","eighth","ninth","tenth","eleventh","twelth"},b={"a Partridge in a Pear Tree\n","and ","2 Turtle Doves\n","3 French Hens\n","4 Calling Birds\n","5 Golden Rings\n","6 Geese a Laying\n","7 Swans a Swimming\n","8 Maids a Milking\n","9 Ladies Dancing\n","10 Lords a Leaping\n","11 Pipers Piping\n","12 Drummers Drumming\n"};if(y==0){p=1;}if(d>358){c=d-358-p;}else if(d<6){c=d+7;}else{t.Dump();return;}if(c==1){o+=z[0]+x+b[0];}else{o+=z[c-1]+x;for(int i=c;i>=0;i--){o+=b[i];}}o.Dump();}
Formatted:
void Main()
{
var w=DateTime.Now;
int y=w.Year%4,d=w.DayOfYear,c=0,p=0;
string t="Well Z\nWhen the kids start singing and the band begins to play\nOh Z\nSo let the bells ring out for X".Replace("Z","I wish it could be X every day").Replace("X","Christmas"),
o="On the ",x=" day of Christmas\nmy true love sent to me:\n";
string[]z={"first","second","third","forth","fifth","sixth","seventh","eighth","ninth","tenth","eleventh","twelth"},
b={"a Partridge in a Pear Tree\n","and ","2 Turtle Doves\n","3 French Hens\n","4 Calling Birds\n","5 Golden Rings\n","6 Geese a Laying\n",
"7 Swans a Swimming\n","8 Maids a Milking\n","9 Ladies Dancing\n","10 Lords a Leaping\n","11 Pipers Piping\n","12 Drummers Drumming\n"};
if(y==0)
{
p=1;
}
if(d>358)
{
c=d-358-p;
}
else if(d<6)
{
c=d+7;
}
else
{
t.Dump();
return;
}
if(c==1)
{
o+=z[0]+x+b[0];
}
else
{
o+=z[c-1]+x;
for(int i=c;i>=0;i--)
{
o+=b[i];
}
}
o.Dump();
}
It's big! It's mean! It's ugly! It's...
Java: 894 887 883 882 bytes
Golfed:
class C{public static void main(String[]a){java.util.Calendar d=java.util.Calendar.getInstance();String p="a Partridge in a Pear Tree\n",t="Well Z\nWhen the kids start singing and the band begins to play\nOh Z\nSo let the bells ring out for X".replaceAll("Z","I wish it could be X every day"),r="";String[]s=(" day of X\nMy true love gave to me:\nçfirstçsecondçthirdçfourthçfifthçsixthçseventhçeighthçninthçtenthçeleventhçtwelfthç Turtle Doves\nç French Hens\nç Calling Birds\nç Golden Rings\nç Geese a LayY\nç Swans a SwimmY\nç Maids a MilkY\nç Ladies DancY\nç Lords a LeapY\nç Pipers PipY\nç Drummers DrummY\n").replaceAll("Y","ing").split("ç");int n=d.get(d.DAY_OF_YEAR),o=(n>358)?(n-358):(n<6)?(n+7):-1,j;if(o==-1)r=t;else{r+=("On the "+s[o]+s[0]);for(j=o+11;j-->12;r+=(j-11+s[j]));r+=(o!=1)?"and "+p:p;}System.out.print(r.replaceAll("X","Christmas"));}}
Ungolfed:
class C {
public static void main(String[] a) {
java.util.Calendar d = java.util.Calendar.getInstance();
String p = "a Partridge in a Pear Tree\n", t = "Well Z\nWhen the kids start singing and the band begins to play\nOh Z\nSo let the bells ring out for X".replaceAll("Z", "I wish it could be X every day"), r = "";
String[] s = (" day of X\nMy true love gave to me:\nçfirstçsecondçthirdçfourthçfifthçsixthçseventhçeighthçninthçtenthçeleventhçtwelfthç Turtle Doves\nç French Hens\nç Calling Birds\nç Golden Rings\nç Geese a LayY\nç Swans a SwimmY\nç Maids a MilkY\nç Ladies DancY\nç Lords a LeapY\nç Pipers PipY\nç Drummers DrummY\n").replaceAll("Y", "ing").split("ç");
int n = d.get(d.DAY_OF_YEAR), o = (n > 358) ? (n - 358) : (n < 6) ? (n + 7) : -1, j;
if (o == -1) {
r = t;
} else {
r += ("On the " + s[o] + s[0]);
for (j = o + 11; j-- > 12; r += (j - 11 + s[j]));
r += (o != 1) ? "and " + p : p;
}
System.out.print(r.replaceAll("X", "Christmas"));
}
}
After messing with it a lot and gaining 14 bytes, I think I'll stop fiddling with it.
And yes, I know that, on leap years, my idea may have a bit of an issue, but... it was my way to cut a few bytes off the code. Oh well.
Javascript (665)
__=new Date("12/31");M=_.getMonth();D=_.getDate();d=M?(M==11)*(D-24):D+7;if(!d||d>12)s="Well K\nWhen the kids start singing and the bands begin to play\nOh K\nSo let the bells ring out for Christmas".replace(/K/g,"I wish it could be Christmas every day");else{for(s="On the "+"0first0second0third0fourth0fifth0sixth0seventh0eight0ninth0tenth0elevent0twelth".split(0)[d]+" day of Chirstmas\nmy true love sent to me:";--d;)s+="\n"+(d+1)+" "+"0Turtle Doves0French Hens0CallZ Birds0Golden RZs0Geese a LayZ0Swans a SwimmZ0Maids a MilkZ0Ladies DancZ0Lords a LeapZ0Pipers PipZ0Drummers DrummZ".split(0)[d].replace("Z","ing");s+="\n"+(D!=25?"and ":"")+"a Partridge in a Pear Tree"}alert(s)
You can test it by adding parentheses to the first new Date i.e. change:
_=new Date;M=_...
to
_=new Date("1/5");M=_...
Here it is beautified:
_ = new Date("12/31");
M = _.getMonth();
D = _.getDate();
d = M ? (M == 11) * (D - 24) : D + 7;
if (!d || d > 12) s = "Well K\nWhen the kids start singing and the bands begin to play\nOh K\nSo let the bells ring out for Christmas".replace(/K/g, "I wish it could be Christmas every day");
else {
for (s = "On the " + "0first0second0third0fourth0fifth0sixth0seventh0eight0ninth0tenth0elevent0twelth".split(0)[d] + " day of Chirstmas\nmy true love sent to me:"; --d;) s += "\n" + (d + 1) + " " + "0Turtle Doves0French Hens0CallZ Birds0Golden RZs0Geese a LayZ0Swans a SwimmZ0Maids a MilkZ0Ladies DancZ0Lords a LeapZ0Pipers PipZ0Drummers DrummZ".split(0)[d].replace("Z", "ing");
s += "\n" + (D != 25 ? "and " : "") + "a Partridge in a Pear Tree"
}
alert(s)
CJam, 557 550 530 528 522 519 bytes
et3<(;" Christmas":P;:(31b7+372%_C<{"On the ""first second third"S/"four fif six seven eigh nin ten eleven twelf"S/"th"f++@:X=" day of"P"
my true love sent to me:
""and a Partridge in a Pear Tree."a[D,2>Sm*"Turtle Dove
French Hen
Calling Bird
Golden Ring
Geese a Lay
Swans a Swimm
Maids a Milk
Ladies Danc
Lords a Leap
Pipers Pip
Drummers Drumm"N/'s4*"ing"a7*+]z+X)<W%N*X!{4>}*}{;"Well"" I wish it could be"P" every day
"++_"When the kids start singing and the band begins to play
Oh"\"So let the bells ring out for"P}?
Test it here. To try out different dates, replace et3<(; with something like [12 25].
There's probably still room for improvement.
et "Read the current datetime as an array [year month day hour ...].":
3< "Discard hours, minutes etc.";
(; "Discard year.";
" Christmas":P; "Store the string in P and discard.";
:( "Decrement month and day.";
31b "Interpret as base-31 digits. So on [12 25] we get 365 (what a coincidence).
On [12 31] we get 371. On [1 1] we get 0. On [1 5] we get 4.";
7+ "Add 7.";
372% "Take modulo 372. Now the 12 days result in 0 to 11, others are greater.";
_C< "Duplicate and check if it's less than 12.";
{...}{...}? "Run the first block for the 12 days, the second block otherwise.";
"On the 12 days:";
"On the " "Push the string.";
"first ... third"S/ "Push first to third. Split by spaces.";
"four ... telf"S/ "Push other ordinal numbers, split by spaces.";
"th"f+ "Add th to each.";
+ "Append to get first to twelfth.";
@:X "Pull day number to the top. Store in X.";
= "Select ordinal number.";
" day of"P "Push ` day of Christmas`.";
"\nmy true...\n" "Push that string, too".;
"and a Part..."a "Push day 1 string and wrap in array.";
[ "Remember beginning of array.";
D,2> "Push range [2 3 ... 12].";
Sm* "Append a space to each.";
"Turtle..."N/ "Push all the gifts. Split into lines.";
's4* "Push `ssss`.";
"ing"a7* "Push an array with 7 copies of `ing`.";
+ "Add the two.";
] "Close array, containing numbers, gifts and endings.";
z "Zip/transpose the array.";
+ "Add day-1 line.";
X) "Push day and decrement.";
< "Slice off unwanted days.";
W% "Reverse array.";
N* "Join lines with line breaks.";
X! "Logical not of day, is 1 on day 1 and 0 on all other days.";
{4>}* "On day 1, remove first 4 characters (`and `).";
"On all days:";
; "Discard day from stack.";
"Well" "Push the string.";
" I..."P"...day\n" "Push the rest of the line in 3 strings.";
++_ "Join those three into one, and duplicate.";
"When...\nOh" "Push next line and `Oh`.";
\ "Swap with duplicate line.";
"So ... for"P "Push final line.";
Erlang, 748 bytes
A 7-bit clean version without gzip-9 is 748 bytes:
f()->[maps:get(C,#{$N=>"ing",$x=>10,$q=>"th",$z=>" Christmas"},C)||C<-s(t(calendar:local_time()))].
t({{_,1,D},_})->D+7;t({{_,12,D},_})->D-24;t(_)->1.
s(X)when X<1;X>12->L=" I wish it could bez every dayx","Well"++L++"When qe kids start sNN and qe band begins to playxOh"++L++"So let qe bells rN out forz";
s(I)->"On qe "++element(I,{"first","second","qird","fourq","fifq","sixq","sevenq","eighq","ninq","tenq","elevenq","twelq"})++" day ofzxmy true love sent to me:x"++r(I).
r(0)->"";r(I)->element(I,{"a Partridge in a Pear Tree","2 Turtle Dovesxand ","3 French Hensx","4 CallN Birdsx","5 Golden RNsx","6 Geese a LayNx","7 Swans a SwimmNx","8 Maids a MilkNx","9 Ladies DancNx","10 Lords a LeapNx","11 Pipers PipNx","12 Drummers DrummNx"})++r(I-1).
A gzip-9+base64 solution is 750 bytes long:
f()->s(t(calendar:local_time())).
t({{_,1,D},_})->D+8;t({{_,12,D},_})->D-23;t(_)->1.
s(I)->try element(I,binary_to_term(base64:decode("g1AAAAkQeNrdlF9OGzEQxsNrJF44wXeEhtK/jyUqRQoCARLPTnYSW+u1oxlv0jz3BL1C71D1Cj1C79BDtOOQhQqpCKv0D5VW8u5a883vmxnbbte9jxfkPQ6xdGLhEiax9RXGhH3LTlJjBLQgXqEyq/6FpYBkCbWrBJIMJ4gLM31gQrXeGueXMek/QYqYe407tnfNcBbhKV0KKZiAs3ZsE6aRryPq3unxJcnUsaQcijj9QbHfrJC4Jfi4IAiFlGEaetk3OFFsdtWM4AL0kwzjnInqHm1EhSZRXdxU/bnoLs5bTp4w1B3p5xLcloc3eZJ1XJLmMV4zhYnFGwpSmvRdV7GoUbYg6x72jfe5D68UV36N4v1V36ZFEE9wEH2l43eqIHK/TB+6tru3RUxPcUAkpGIjs1KW3wr56Wo2F4pQgvkMZ0ujp9Ho6pomg/5R8s8bcnIzWwT+HEcmXzQGR87XGfNvW/mysRJcWQteKFzlSDA0YZIh/z1rX7s7qXC6Bo8wiry2MiIzz5gPwO23biZ98XEaDHDi5sSSl8z5ICuwtdP1e0m+zP8uhtw2Ta7A+mVdg/+hKN8Bkz8M5Q==")))catch _:_->s(1)end.
An UTF-8 encoded Erlang function is 421 characters (935 bytes).
f()->s(t(calendar:local_time())).
t({{_,1,D},_})->D+8;t({{_,12,D},_})->D-23;t(_)->1.
s(I)->try element(I,binary_to_term(<<<<(C-$㐀):14>>||C<-"哔㐀㐤䑸檷䵅焸伱㠱怶悑券摝汈佊玏㵊塐專㔒染孡㵯徵峆䫽㳳欄捐拵㟔㸽䒻焄䋓垐啂庐嚯栏奕挮浫柍濦斝憻䮽埅牃栺整䲸䔢仇椕斡㯜愹䙣㔭㘅溄暫玡乘㖐㶵廁㴠撞㰋䃟䨄㻗刚淥朞壽㖊娞泓拙母倅戒奴㸩娠㼷䶰䞦填显彻己㵲克㪐傊䈿䠛㭾悐戉压咀㲅夘䖧彤欸䡛㭭䨳吂焤擎䉲㷪㮛䡈䢙䕝欕䏛宠拎䫓巣㝐凩淄應东歹墝䧉㾘敞䃡䲜䡬㹒媽㧕勆屑憈䊱濚䇷扃滱䕝犍沿䥝犙㤐䟜㔇檗坷庈㬫焰厺憮潴䤱䍱䐉㹆㲎杒妷撯宥帶㧢夈㿤䁧䛨湽㮣庚㶠珥㯋䌛傜圵怓爜䗉姳䐙㯎槆匶煯液恄姅堭刨䬹䢃㓑喒㱿柖慾漻幜㾠丼撊挭圢㳏䎘㟰䋛冸婽灜䖠旃囦攤嵼柤含怭儿䧭㶾朿曨佰橍徰䎦䥶㟿届䇰㩌猌浀㐀㐀㐀">>))catch _:_->s(1)end.
Python 2, 681 676 673 670 667 bytes
import time
N=time.localtime();D,M=N.tm_mday,N.tm_mon
Q=((D<6>M<2)*(31+D)+(M>11)*D)-24
print["Well%sWhen the kids start singing and the band begins to play\nOh%sSo let the bells ring out for~"%((" I wish it could be~ every day\n",)*2),"On the %s day of~\nmy true love sent to me:\n"%("twel first second third four fif six seven eigh nin ten eleven".split()[Q%12]+"th"*(Q>3))+"\n".join("%d %s"%(i,"Turtle Doves$French Hens$Calling Birds$Golden Rings$Geese a Lay$Swans a Swimm$Maids a Milk$Ladies Danc$Lords a Leap$Pipers Pip$Drummers Drumm".split("$")[i-2]+"ing"*(i>5))for i in range(Q,1,-1))+"\nand "*(Q>1)+"a Partridge in a Pear Tree"][Q>0].replace("~"," Christmas")
I tried competing against CJam... and failed as expected. Maybe if I could figure out how to zlib, but I dunno...
(Thanks to @FryAmTheEggman for suggestions via chat)