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)
Welcome to PPCG, please refer to the sandbox if you have an idea for challenges.
– devRicher – 2016-12-25T11:21:33.1905Yeah 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.6533Golfy 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.3371No, 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