12 Tage Golf

13

Herausforderung

Geben Sie an jedem der 12 Weihnachtstage den entsprechenden Vers "12 Weihnachtstage" entsprechend dem Datum aus, andernfalls den Refrain "Ich wünschte, es könnte Weihnachten sein, jeden Tag".

Führende und / oder nachfolgende Zeilenumbrüche ( \n) und nachfolgende Leerzeichen sind zulässig. Sie dürfen nicht aus externen Quellen lesen.

Grundsätzlich müssen Sie das Systemdatum auslesen und den entsprechenden Vers der "12 Tage Weihnachten" ausgeben.

12 Weihnachtstage

Die zwölf Weihnachtstage sind die festliche christliche Jahreszeit, die am Weihnachtstag (25. Dezember) beginnt und am 5. Januar endet.

Beispiele

Wenn das Datum der 25. Dezember ist (drucken Sie den kürzesten / ersten Vers aus):

On the first day of Christmas 
my true love sent to me:
a Partridge in a Pear Tree

Wenn das Datum der 31. Dezember ist (drucken Sie den siebten Vers):

On the seventh day of Christmas
my true love sent to me:
7 Swans a Swimming
6 Geese a Laying
5 Golden Rings
4 Calling Birds
3 French Hens
2 Turtle Doves
and a Partridge in a Pear Tree

Wenn das Datum der 5. Januar ist (drucken Sie den längsten / letzten / 12. Vers aus):

On the twelth day of Christmas
my true love sent to me:
12 Drummers Drumming
11 Pipers Piping
10 Lords a Leaping
9 Ladies Dancing
8 Maids a Milking
7 Swans a Swimming
6 Geese a Laying
5 Golden Rings
4 Calling Birds
3 French Hens
2 Turtle Doves
and a Partridge in a Pear Tree

Wenn das Datum nicht im Bereich vom 25. Dezember bis einschließlich 5. Januar liegt:

Well I wish it could be Christmas every day
When the kids start singing and the band begins to play
Oh I wish it could be Christmas every day
So let the bells ring out for Christmas 

Frohe Weihnachten!

Beta-Zerfall
quelle
Müssen wir also ein Programm schreiben, das das Systemdatum liest und entsprechend druckt? Ihre Fragen scheinen unvollständig zu sein und enthalten nicht so viele Details.
Optimierer
8
Noch eine Herausforderung bei der Klartextkomprimierung? Kein Fan.
John Dvorak
Java-Leute amüsieren sich nicht, werden aber versuchen, zu entsprechen.
Rodolfo Dias
3
Dies ist kein Duplikat. Dieses Programm war eine einfache Herausforderung in Bezug auf die Komplexität von Kolmogrov - dazu gehört das Lesen des Datums und die Ausgabe auf der Grundlage dieses Messwerts.

Antworten:

6

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

Teste es hier. Ersetzen Sie, um andere Daten auszuprobierenet3<(; durch etwas wie [12 25].

Es gibt wahrscheinlich noch Raum für Verbesserungen.

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.";
Martin Ender
quelle
5 Golden R(ing)inakzeptabel? Verdammt! Gibt es eine Möglichkeit, die -ingEndung und die -s Endung auf die Zahl 5 anzuwenden ?
Level River St
5

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

Ich habe versucht, gegen CJam anzutreten ... und bin wie erwartet gescheitert. Vielleicht, wenn ich herausfinden könnte, wie man zlib, aber ich weiß nicht ...

(Danke an @FryAmTheEggman für die Vorschläge via Chat)

Sp3000
quelle
4

Es ist groß! Es ist gemein! Es ist hässlich! Es ist...

Java: 894 887 883 882 Bytes

Golf gespielt:

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"));
    }
}

Nachdem ich viel damit herumgespielt und 14 Bytes gewonnen habe, werde ich wohl aufhören, damit herumzuspielen.

Und ja, ich weiß, dass meine Idee in Schaltjahren vielleicht ein kleines Problem hat, aber ... es war meine Art, ein paar Bytes vom Code abzuschneiden. Naja.

Rodolfo Dias
quelle
1
Sie sind zu hart in Java ...
Beta Decay
1
@BetaDecay Vielleicht bin ich. Und vielleicht sollte ich versuchen, in etwas anderem als Java Golf zu spielen: P
Rodolfo Dias
Denken Sie, Sie können Code-Syntax-Hervorhebungen in Ihren Code einfügen? Ich bevorzuge farbigen Code gegenüber Schwarz-Weiß-Code. Es lenkt mich von der Tatsache ab, dass jeder Code in irgendeiner Form Maschinencode darstellt.
TheNumberOne
@TheBestOne Ich würde es gerne tun ... wenn ich herausfinden würde, wie ich es aktivieren kann.
Rodolfo Dias
3
Versuchen Sie es <!-- language: lang-java -->vor einem Codeblock. Verwenden Sie <!-- language-all: lang-java -->für alle Codeblöcke in Ihrem Dokument. Weitere Informationen finden Sie unter codegolf.stackexchange.com/editing-help
TheNumberOne
1

Erlang, 748 Bytes

Eine 7-Bit-Clean-Version ohne gzip-9 hat 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).

Eine gzip-9 + base64-Lösung ist 750 Byte lang:

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.

Eine UTF-8-codierte Erlang-Funktion besteht aus 421 Zeichen (935 Byte).

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.
Paul Guyot
quelle
0

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)

Sie können es testen, indem Sie Klammern zur ersten new DateÄnderung hinzufügen :

_=new Date;M=_...

zu

_=new Date("1/5");M=_...

Hier ist es verschönert:

_ = 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)
soktinpk
quelle
0

C # In Linqpad - 866 Bytes

Naja, zumindest hat es Java geschlagen;) Schaltjahre werden im Code behandelt.

Unformatiert:

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();}

Formatiert:

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();
}
Tsavinho
quelle
Wie geht das mit Schaltjahren um?
Beta Decay
@BetaDecay Am Anfang verwende ich einen Modul für das Jahr int y=w.Year%4. Wenn das Modulo y0 ist, füge ich cmit Hilfe von eins hinzu p.
Tsavinho