Merry Golfmas, Everyone!

35

It's Christmas everybody, and here's a code-golf challenge to celebrate. You need to make a program to print out a present. Specifically, the words "Merry Christmas". BUT, there is a catch: this program must only work if it is the 25th of December. If the code is run on any other day, then the program should crash.

This is Code-Golf, so the answer with the least amount of bytes wins.

Merry Christmas!

Leo

Posted 2016-12-25T11:16:18.257

Reputation: 1 256

Welcome to PPCG, please refer to the sandbox if you have an idea for challenges.

– devRicher – 2016-12-25T11:21:33.190

5Yeah that was ermmmmm. .. yeah 25th sorry – Leo – 2016-12-25T11:35:46.900

2

Related challenges: Merry Christmas (and a Happy New Year), Christmas Countdown, and Is it Christmas?

– PhiNotPi – 2016-12-25T12:42:29.653

3Golfy Codemas! :) – Luis Mendo – 2016-12-25T13:05:09.907

You say the program must crash. Does exiting without an error count? – James – 2016-12-25T13:19:51.337

1No, it must be a crash. You can't quit the aplication – Leo – 2016-12-25T13:25:54.110

Just to be extra clear, does an error count if it stops the application? – user41805 – 2016-12-25T13:58:06.327

Yes that counts – Leo – 2016-12-25T13:58:38.333

2@PhiNotPi Those challenges are different. This is not asking for a countdown and does not involve waiting to give output – Leo – 2016-12-25T14:04:42.667

1I think these challenges are very different as waiting for a date is a completely different operation to checking if it is one – Blue – 2016-12-25T15:11:45.357

Are you sure this is [tag:kolmogorov-complexity]? KC questions are normally about compressing a constant output. Merry Christmas can't really be compressed, this post is more about date/time verification. – FlipTack – 2016-12-25T15:20:37.013

@Flp.Tkc I know. I didn't choose the tag myself – Leo – 2016-12-25T15:23:05.673

25 of December in what timezone? Local timezone? UTC? – Oriol – 2016-12-26T17:16:22.287

do I leap years? – dkudriavtsev – 2016-12-27T03:20:18.300

Answers

8

Pyke, 21 bytes

.dↄґ6C65h*325q/Al

Try it here!

     C65h*        -   multiply the day by the (current month + 1)
          325q    -  ^ == 325
    6         /   - 6 / ^
.dↄґ              -  load "merry christmas"
               Al - ^.capwords()

Or 18 bytes noncompetitive.

.dↄґ6Cs6Y1q/Al

Exactly the same except for this section:

Cs6Y1q 
C      -    get_time()
 s6    -   add 1 week
   Y   -  get day of the year
    1q - ^ == 1

Try it here!

Blue

Posted 2016-12-25T11:16:18.257

Reputation: 26 661

This fails if it's October 30th, does it not? – Magic Octopus Urn – 2016-12-27T15:14:42.077

1@carusocomputing 30 * (10+1) = 330 not 325 – Blue – 2016-12-27T16:00:51.670

6

JavaScript, 55 53 46 bytes

Note: this has only been tested in Google Chrome, program may behave differently from browser to browser (or device to device)

2 bytes saved thanks to @ConorO'Brien

7 bytes saved thanks to @ETHProductions

alert(/c 25/.test(Date())?"Merry Christmas":a)

Exits with Uncaught ReferenceError: a is not defined if the date is not Dec 25. I'm not really sure if this counts as crashing

alert(/c 25/.test(Date())?"Merry Christmas":a)

user41805

Posted 2016-12-25T11:16:18.257

Reputation: 16 320

How about .slice(6,10)=="c 25"? – Conor O'Brien – 2016-12-25T16:25:22.217

@ConorO'Brien Thanks! That's smart :) – user41805 – 2016-12-25T16:28:47.197

@ETHproductions I can't think of any day or month that ends in c (Oct comes close, but still doesn't satisfy the regex). Thanks for the tip! – user41805 – 2016-12-25T18:30:55.647

The result of Date() is completely implementation dependent. For example, I expect it to vary with the language and location of the machine. – Oriol – 2016-12-26T17:15:18.093

@Oriol Then I will specify the browser in my answer – user41805 – 2016-12-26T17:18:26.417

5

PHP, 39 38 bytes, not competing (doesn´t crash)

<?=date(md)-1225?"":"Merry Christmas";

or

<?date(md)-1225?die:0?>Merry Christmas

or

<?=["Merry Christmas"][date(md)-1225];

Titus

Posted 2016-12-25T11:16:18.257

Reputation: 13 814

Can anyone golf 4 bytes off date(Lz)%1001-358? :D – Titus – 2016-12-25T12:08:38.637

3Does this crash? – edc65 – 2016-12-25T21:26:33.997

You can leave out "" in the first code which saves you 2 Byte. If it wasn't for damn leap years, you could save 2 Byte more by replacing md by z and 1225 by the number of the day of the year of December 25th. – UTF-8 – 2016-12-25T22:34:02.993

1An alternative: eval((date(md)^TQZZ).'"Merry Christmas";'); (43 bytes) – Ismael Miguel – 2016-12-25T22:41:17.457

@UTF-8: If I remove the "", the ternary result will be 1, not empty. And right, the damn leap years. This would be shorter for New Years Day. – Titus – 2017-01-04T00:17:46.160

@Titus I'm pretty sure I checked. I might be wrong, though, and now checked, again. It prints -1121, not 1, which is great because now we have 3 different results. – UTF-8 – 2017-01-04T00:24:12.003

@edc65: Uhm no. Sorry, didn´t catch that part. Ismael´s alternative does. – Titus – 2017-01-04T00:25:26.313

1@UTF-8: Your´re right. I mostly use the Elvis for boolean values; and that would print 1. This would print the result of the calculation. and 0104-1225 is 1121. – Titus – 2017-01-04T00:29:28.890

@Titus I can't believe I didn't know that operator exists and just learned something new. Thanks. :) – UTF-8 – 2017-01-04T00:38:17.037

5

Python 3, 66 63 bytes

Thanks to ideas from JavaScript / ES answers here I managed to squeeze some bytes. Index a dictionary - non-existent keys will raise a KeyError. The following code works in local time zone

import time;print({1:'Merry Christmas'}['c 25'in time.ctime()])

The output format for ctime isn't locale-dependent - the format is always ~ 'Sun Dec 25 19:23:05 2016'. Since only in December does the 3-letter abbreviation end with c, it is safe to use 'c 25'in time.ctime() here.


Previous version:

This works in UTC time zone. For local time zone one needs to s/gm/local for 3 more bytes. For Python 2, one can remove parentheses from print for 65 bytes.

import time;print({(12,25):'Merry Christmas'}[time.gmtime()[1:3]])

The construct throws KeyError on other dates:

>>> import time;print({(1,1):'Happy New Year'}[time.gmtime()[1:3]])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: (12, 25)

Antti Haapala

Posted 2016-12-25T11:16:18.257

Reputation: 341

Does this crash on other days (it's supposed to)? – Erresen – 2016-12-25T13:29:10.683

2

I can't get this one to run as it objects to the tuple as a key Try it online!. If you change it to import time;print{'2512':'Merry Christmas'}[time.strftime("%d%m")] and label it Python 2 it's still 66 bytes and crashes with a KeyError on dates other than 25 Dec.

– ElPedro – 2016-12-25T13:43:14.170

@ElPedro oops :D should have been 1:3, I copied my test code by accident – Antti Haapala – 2016-12-25T16:55:01.000

Picked up on that when I borrowed your gmtime() idea for my answer. Hope you don't mind :-) – ElPedro – 2016-12-25T17:03:51.577

4

R, 52 61 58 bytes

`if`(format(Sys.Date(),"%m%d")=="1225","Merry Christmas",)

If the current date is not the 25th of December then an error is returned because no third argument is supplied to if.

Edit: Fixed a silly error

Billywob

Posted 2016-12-25T11:16:18.257

Reputation: 3 363

Sorry about my little typo. I meant to say 25tg – Leo – 2016-12-25T11:36:46.287

This only works this year though! – Erresen – 2016-12-25T12:33:07.407

@Erresen Ah right, silly mistake. Fixed now though. – Billywob – 2016-12-25T12:43:53.947

4

Python 2, 68 67 65 bytes

-1 with thanks to @muddyfish

Thanks to @AnttiHaapala for the idea that saved another couple.

import time;print['Merry Christmas'][(12,25)!=time.gmtime()[1:3]]

Try it online!

Throws an IndexError if not 25th Dec.

Non-competing version for 59 bytes as it only works for non Leap years (uses day of year which is 360 this year but 361 in leap years)

import time;print['Merry Christmas'][360!=time.gmtime()[7]]

ElPedro

Posted 2016-12-25T11:16:18.257

Reputation: 5 301

Can't you save a byte by using a list instead of a tuple? – Blue – 2016-12-25T13:56:58.017

@muddyfish Thanks, good catch. – ElPedro – 2016-12-25T13:58:36.133

Nice one, my idea was 2 extra bytes :P

– FlipTack – 2016-12-25T15:29:44.573

Thanks. That was also my 67 byte version until I commented on the answer from @AnttiHaapala and thought about gmtime() to shave a couple off. I have to admit, I wish there was more I could do with the day-of-year idea though. – ElPedro – 2016-12-25T15:40:17.190

You can save 1 byte with: time.ctime()[6:10]!='c 25' – Max – 2016-12-26T11:30:17.907

4

My first time around here... Started with the best language ever for this job:

Java, 200 188 bytes (thanks to @Daniel Gray), 186 bytes removing "ln" from print.

import java.util.*;public class a{public static void main(String[]r){Calendar c=Calendar.getInstance();if(!(c.get(2)==11&&c.get(5)==25)){int i=1/0;}System.out.print("Merry Christmas");}}

Try it here!

Bonifacio

Posted 2016-12-25T11:16:18.257

Reputation: 151

1Welcome to PPCG! Nice first post, even though java isn't quite the shortest. – Rɪᴋᴇʀ – 2016-12-26T20:17:55.953

1You can change the Calendar for * and save a few bytes. You could also shorten the name of the args parameter in the main method, I think... – Daniel Gray – 2016-12-27T11:23:57.220

@Daniel Gray, You are absolutely right, thanks! – Bonifacio – 2016-12-27T13:39:42.443

1Welcome! You can save 10 bytes if you replace "public class" with "interface" and remove the public modifier from main, making it "interface a{static void main..." This, however, will prevent Compilejava from being able to run it online. – Zavada – 2016-12-27T16:55:40.267

3

MATL, 34 33 bytes

'Merry Christmas'IHh&Z'5U12h=?}Yl

This works in current version (19.7.0) of the language. To cause the error, the following code exploits the fact that the logarithm of a string gives an error (this may change in future versions).

Try it online!

Explanation

'Merry Christmas'  % Push this string
IHh                % Push 3, then 2, concatenate: gives array [3 2]
&Z'                % Get 3rd and 2nd outputs of clock vector: current day and month
5U12h              % Push 5, square, push 12, concatenate: gives [25 12]
=                  % Compare if corresponding entries are equal in the two arrays
?                  % If all entries are equal: do nothing
}                  % Else
  Yl               %   Logarithm. Gives an error when applied on a string
                   % End (implicit). Display (implicit)

Luis Mendo

Posted 2016-12-25T11:16:18.257

Reputation: 87 464

3

C# / CS Script 106 100 99 bytes

99 byte solution

using System;int i;Console.WriteLine(DateTime.Now.ToString("dM")=="2512"?"Merry Christmas":i/0+"");

Try it here!

100 byte solution (prefer this one... a bit different)

using System;int i;Console.WriteLine(DateTime.Now.AddDays(7).DayOfYear==1?"Merry Christmas":i/0+"");

Explained:

using System;
int i;

// if today plus 7 days is the first day of the year, then it's xmas!
Console.WriteLine(DateTime.Now.AddDays(7).DayOfYear==1
    ? "Merry Christmas"

// otherwise divide i by 0
    : i/0+"");

DateTime.Now.AddDays(7).DayOfYear==1 is one byte shorter than DateTime.Now.ToString("ddMM")=="2512" but 1 byte longer than DateTime.Now.ToString("dM")=="2512"

Erresen

Posted 2016-12-25T11:16:18.257

Reputation: 449

1You can use $"{DateTime.Now:dM}"=="2512". dM is ambiguous, but not for "2512". – Kobi – 2016-12-25T13:15:45.757

@Kobi I can't use string interpolation for CS Script :( – Erresen – 2016-12-25T13:22:03.080

1You can if you use LinqPad (e.g. $"{DateTime.Now:dM}"=="2512"?"Merry Christmas":1/1-1+"" 55 bytes) =) – Kenneth K. – 2016-12-25T23:13:45.383

Why int i and notjust 1/0? – NoOneIsHere – 2016-12-26T03:54:27.897

@SeeOneRhino the compiler recognises that as an error and won't compile – Erresen – 2016-12-26T10:14:08.870

@KennethK. I'll have to try linqpad if it can save me a few bytes! – Erresen – 2016-12-26T10:14:48.737

@KennethK. Tried Linqpad, but your 55 byte solution doesn't work. 1/1-1 is zero not an error, as the division is done before subtraction, and 1/(1-1) doesn't compile. It's a nice tool though - thanks for the pointer. – Erresen – 2016-12-26T20:42:45.547

1@Erresen Ah, my mistake. I didn't test thoroughly enough. Tweaked: $"{DateTime.Now:dM}"=="2512"?"Merry Christmas":"".Remove(1) (59 bytes) – Kenneth K. – 2016-12-27T16:26:58.787

3

QBIC, 48 bytes

~left$$|(_D,5)=@12-25||?@Merry Christmas|\?a(12)

Explanation:

~             IF
left$$|(_D,5) the date string starts with
=@12-25|      the string "12-25"
|             THEN
?@Me..as|     PRINT "Merry Christmas"
\             ELSE
?a(12)        Print the twelfth index of an undefined array. 
              Since there are only 11 elements in undefined arrays, this 
              results in an index-out-of-bounds error.    
The the IF statement is auto-closed by QBIC.

This assumes American MM-DD date notation. This would be shorter if I'd finally make a Substring function in QBIC.

steenbergh

Posted 2016-12-25T11:16:18.257

Reputation: 7 772

What happens on days that aren't Christmas? Does it crash as it's supposed to? – Erresen – 2016-12-25T13:28:13.160

@Erresen it does now. – steenbergh – 2016-12-25T13:29:38.357

3

05AB1E, 32 21 bytes

Saved 11 bytes thanks to Adnan's string compression :) .

1žfže‚12D·>‚Q÷”ÞٌΔ×

Explanation

 žfže‚                Push [current month, current day]
      12D·>‚          Push [12, 25]
            Q         Push tmp = 1 if the two arrays are equal, tmp = 0 otherwise
1            ÷        Evaluate x = 1/tmp. If tmp = 0 a division by 0 exception is thrown
              ”ÞÙŒÎ”× Implicitly display "Merry Christmas" x times

Try it online!

I did what came to mind first, so there may be better approaches for this one. But PPCG deserves a Merry Christmas in 05AB1E as well ;) .

Osable

Posted 2016-12-25T11:16:18.257

Reputation: 1 321

Also, x is short for duplicate and double :). – Adnan – 2016-12-26T17:32:50.820

2

C#/CS Script, 96 Bytes, Mostly Plagiarized from Erresen

using System;Console.WriteLine(DateTime.Now.AddDays(7).DayOfYear==1?"Merry Christmas":1/0+"");

Deletes the int i declaration in favor of hard coding the division. I would leave this as a comment but don't have the reputation.

Hunter Robertson

Posted 2016-12-25T11:16:18.257

Reputation: 41

Welcome to PPCG! Nice first post! Don't worry about the comment/answer thing, it doesn't matter too much. – Rɪᴋᴇʀ – 2016-12-25T19:23:57.747

2

bash + Unix utilities, 51 49 47 bytes

((`date +%m%d`-1225))&&${};echo Merry Christmas

*Thanks to @KenY-N for pointing out that the quotes in the echo can be removed, and to @IporSircer for reducing the condition size by 2 bytes.

Mitchell Spector

Posted 2016-12-25T11:16:18.257

Reputation: 3 392

That gives me bash: ${}: bad substitution error. Also you can drop the quotes from Merry Christmas to save two bytes. Furthermore, [ \date +%m%d` = 1225 ]&&echo Merry Christmas` works for me, equalling my 45 bytes.

– Ken Y-N – 2016-12-27T03:19:30.617

1@KenY-N The error is intentional: the program is supposed to crash on days other than Christmas. Thank you for mentioning that the quotes in the echo can be dropped; I missed that. – Mitchell Spector – 2016-12-27T03:28:29.587

Oops, missed that requirement! Tested out by changing the date string, and I see now that it doesn't crash. Deleted my answer... But, I have an alternative, so let me update it. – Ken Y-N – 2016-12-27T03:55:03.833

Try replacing ${} with !- to beat me by one byte. I'll upvote you as you win. – Ken Y-N – 2016-12-28T00:28:47.293

And now I've saved one more byte, so it's a tie again. – Ken Y-N – 2016-12-28T00:43:55.133

1@KenY-N Thanks, but I'm not going to change ${} to !- since I think the latter will only work correctly on the command line, not in a script (unless you turn history substitution on, which would take additional characters). – Mitchell Spector – 2016-12-28T19:21:19.393

You can still save 2 byte at the beginning and win: ((\date +%m%d`-1225))&&` – Ipor Sircer – 2017-01-04T02:33:19.900

Thanks, @IporSircer, I've made the change. It actually does need && with this variant. (The condition is true if its numerical value is non-zero, which happens when it's not Christmas.) – Mitchell Spector – 2017-01-04T06:54:44.677

1

Groovy, 57 bytes

print new Date().format("Md")=="1225"?"Merry Christmas":b

Crashes on dates other than 25.12. with groovy.lang.MissingPropertyException because b is not defined.

chrki

Posted 2016-12-25T11:16:18.257

Reputation: 533

1

Python 2, 69 77 75 or 72 70 Bytes

import time
if time.strftime("%d%m")=="2512":print"Merry Christmas"
else:1/0

If it doesn't matter if it exits with an error when it is Christmas, then:

import time
if time.strftime("%d%m")=="2512":print"Merry Christmas"
1/0

EDIT:

Thanks @Flp.Tkc for pointing out that I needed to raise an error

-2 Bytes from @Max for pointing out about removing colons from the strftime function

sonrad10

Posted 2016-12-25T11:16:18.257

Reputation: 535

1It's meant to crash if it's not Christmas, this just exits normally. – FlipTack – 2016-12-25T20:36:50.720

You can save 2 bytes removing the colons --> '%d%m' == '2512' – Max – 2016-12-26T11:17:57.307

@Max OK, thanks for the tip. I hadn't used this function before, so I hadn't thought of doing that – sonrad10 – 2016-12-26T11:50:52.063

save another 3 bytes with: time.ctime()[6:10]=='c 25' – Max – 2016-12-26T12:01:16.197

1

Stacked, 42 bytes

Try it here!

('Merry Christmas')'MMDD'date'1225'=¬#out

This creates a single-element array containing namely 'Merry Christmas!'. After, it puts the date into a string with the month followed by the day. It checks for equality with '1225' (Christmas), inverts it with ¬, then gets that member from the preceding array. If it isn't Christmas, this will error with an index error. Otherwise, it prints Merry Christmas. (Change the date in the string to see how it works on other days.)

Conor O'Brien

Posted 2016-12-25T11:16:18.257

Reputation: 36 228

1

Batch, 66 bytes

@echo off
if %date:~0,5%==25/12 echo Merry Christmas&exit/b
if

The trailing newline is significant, as it causes parsing of the if statement to fail. You may need to tweak the date check to match your local date format.

Neil

Posted 2016-12-25T11:16:18.257

Reputation: 95 035

1

CJam, 28

et[C25]#1="Merry Christmas"/

Try it online

Explanation:

et                   push an array of current [year month day hour ...]
[C25]                push the array [12 25] (C=12)
#                    find the position of the 2nd array within the first one
1=                   compare it with 1, resulting in 1 for 1 and 0 otherwise
"Merry Christmas"/   split "Merry Christmas" into pieces of that length
                      (it crashes if the length is 0)
                     at the end, all the pieces are concatenated
                      and printed automatically

aditsu quit because SE is EVIL

Posted 2016-12-25T11:16:18.257

Reputation: 22 326

0

C#.NET, 180 172 171 bytes

Saved 8 bytes thanks to Kritixi Lithos

Saved 1 byte thanks to Kritixi Lithos, again ;)

namespace System{class P{static void Main(string[] args){var d=DateTime.Today;if(d.Day==25)if(d.Month>11){Console.Write("Merry Christmas!");return;}throw new Exception();}}}

Alternative, ungolfed variant:

namespace System //In System, so we don't have to use system.
{
    class Program
    {
        static void Main(string[] args) //Main function.
        {
            var d = DateTime.Today; //Get Today.
            if (d.Day == 25) if (d.Month == 12) //Day has to be 25th, Month has to be 12nd.
                {
                    Console.Write("Merry Christmas!"); return; //Prints.
                }
            throw new NotChristmasException(); //Errors/Crashes the program.
        }
    }
    class NotChristmasException : Exception { } //Holiday exception, hooray!
}

devRicher

Posted 2016-12-25T11:16:18.257

Reputation: 1 609

Can't you give the program a shorter class name? – user41805 – 2016-12-25T11:38:43.337

You could remove some bytes by changing the "NotChristmasException" to something shorter. – Leo – 2016-12-25T11:39:35.203

@FishProHD The NotChristmasException is only in the ungolfed variant. – devRicher – 2016-12-25T11:40:22.373

@KritixiLithos Thanks, changed that. – devRicher – 2016-12-25T11:41:40.497

Oh, so it is. Sorry! – Leo – 2016-12-25T11:42:26.793

Can you throw new Error() in c#? – Roman Gräf – 2016-12-25T16:35:41.763

You can also change the string[] args to string[]a to save a few bytes, I think (I don't know C#, only Java and I think the same tip can apply for both) – user41805 – 2016-12-25T20:42:07.630

You might be able to do if(d.Month>11) instead to save more bytes (since there are no months past #12) – user41805 – 2016-12-25T20:43:15.697

@KritixiLithos Thanks alot again! – devRicher – 2016-12-25T20:48:21.623

You can also change the string[] args to string[]a to save a few bytes :) – user41805 – 2016-12-26T09:55:19.467

1if(d.Day==25&&d.Month>11)Console.Write(...);else throw new Exception() note combined if statements and removal of braces around the Console.Write and replace return with else. Also change var d=DateTime.Now you can get rid of exception throw with perhaps args[-1]; after renaming args to a so a[-1]; (this so not identical to divide by zeros used elsewhere) – pinkfloydx33 – 2016-12-26T10:23:46.993

0

C#, 122 104 bytes

18 bytes saved, thanks to @raznagul

using System;i=>{if(DateTime.Now.AddDays(7).DayOfYear==1)Console.Write("Merry Christmas");else{i/=0;};};

It adds 7 days to the current day, and checks if it is the first day of the year, if yes, it displays "Merry Christmas", otherwise it divides by zero.

Horváth Dávid

Posted 2016-12-25T11:16:18.257

Reputation: 679

The return is not necessary. Use i instead of (). – raznagul – 2016-12-26T21:06:08.047

0

Mathematica, 46 bytes

If[Today[[1,2;;]]=={12,25},"Merry Christmas!"]

JungHwan Min

Posted 2016-12-25T11:16:18.257

Reputation: 13 290

Now saves 2 Bytes over Today – Kelly Lowder – 2016-12-28T14:50:42.663

Also, you need a crash in the False outcome, so I think something like Quit[] or 1/0 should suffice. – Kelly Lowder – 2016-12-28T15:00:18.947

0

Common Lisp, 140

(let((m(multiple-value-list(decode-universal-time(get-universal-time)))))(if(and(eq(nth 3 m)25)(eq(nth 4 m)12))(write"Merry Christmas")(c)))

Crashes with undefined function if the date isn't right.

Harry

Posted 2016-12-25T11:16:18.257

Reputation: 1 189

0

awk, 29 bytes (+ length("Merry xmas"))

v=1225==strftime("%m%d")||1/0

Running it:

$ echo Merry xmas | awk 'v=1225==strftime("%m%d")||1/0'
awk: cmd. line:1: (FILENAME=- FNR=1) fatal: division by zero attempted

Season greeting is piped to awk. strftime returns month+day (for example 1226) and if it matches 1225 $0 record gets outputed. Result of comparison 1225==1226 is placed to v var which is used to divide 1 if the date comparison fails.

James Brown

Posted 2016-12-25T11:16:18.257

Reputation: 663

0

Haskell, 116

Crashes with "Non-exhaustive patterns in function f" if it's not Christmas.

import Data.Time
f(_,12,25)="Merry Christmas"
main=getZonedTime>>=print.f.toGregorian.localDay.zonedTimeToLocalTime

Unfortunately, there's no function that allows you to just immediately get the time in a useful format, so most of this is converting the date formats.

Avery Glitch

Posted 2016-12-25T11:16:18.257

Reputation: 51

0

bash command line, 45 48 49 48 bytes

date +%m%d|grep -q 1225&&echo Merry Christmas||!-
date +%m%d|grep -q 1225||!-;echo Merry Christmas

Similar to Mitchell Spector's, but use grep in silent mode to check for a match, then && will ensure that it only prints on success, and the || causes it to look up history with !-, which gives me this:

-bash: !-: event not found

And it stops execution as !- ; echo foo demonstrates. The bash documentation says that !-n refers to the current command minus n, so perhaps it is being interpreted as !-0, which gives an identical (and non-localised) error message.

Ken Y-N

Posted 2016-12-25T11:16:18.257

Reputation: 396

Good idea, but this doesn't crash on days other than Christmas, like it's supposed to, does it? – Mitchell Spector – 2016-12-27T03:23:49.910

It now gives an error on failure. – Ken Y-N – 2016-12-27T04:03:16.137

1This prints an error message but it continues; it doesn't actually crash. If you replace the . with ${} then it will actually crash rather simply printing an error message and going on. I think crashing requires that the program be terminated at that point. You can tell that yours doesn't terminate by putting an extra ";echo x" at the end and seeing that it gets executed. (That's why I used ${} instead of . in my answer.) I don't know if there's some 1- or 2-character sequence you can use that will cause an actual crash. – Mitchell Spector – 2016-12-27T08:20:37.680

@MitchellSpector: I found a 2 character sequence! – Ken Y-N – 2016-12-28T00:27:10.743

And now back to 48 by switching the logic so I can use ; instead of ||. – Ken Y-N – 2016-12-28T00:43:02.760

!- doesn't work in a program, does it? I think this will only do what you want if you type it from the command line, rather than in a program. (There's probably some setting you can use to turn history on inside a shell script, but that would take additional characters.) – Mitchell Spector – 2016-12-28T02:08:43.217

I've been doing all my testing at the command line, not as a script; I'll highlight that in my title. – Ken Y-N – 2016-12-28T02:21:32.637

Bash is tricky that way -- there are various things that work differently (by default) in a script vs. from the command line. – Mitchell Spector – 2016-12-28T02:23:29.207

0

Ruby, 69 bytes

if Time.now.strftime("%j")=="360";puts "Merry Christmas";else 0/0;end

Works in 2016. Doesn't differentiate between normal and leap years, may need to be adjusted for non-leap years.

dkudriavtsev

Posted 2016-12-25T11:16:18.257

Reputation: 5 781

0

ForceLang, 180 bytes

set s datetime.toDateString datetime.now()
set t "Dec 25"
def c s.charAt i
def d t.charAt i
set i -1
label 1
set i 1+i
if i=6
 io.write "Merry Christmas!"
 exit()
if c=d
goto 1
z.z

(Remember that datetime.toDateString is locale-dependent, so this may not work depending on your locale)

SuperJedi224

Posted 2016-12-25T11:16:18.257

Reputation: 11 342

0

C#, 90 bytes

using System;Console.Write(new[]{"Merry Christmas"}[DateTime.Now.AddDays(7).DayOfYear-1]);

Throws IndexOutOfRangeException if it's not christmas.

Try it here!

Luc

Posted 2016-12-25T11:16:18.257

Reputation: 191