# Merry Golfmas, Everyone!

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!

• Yeah that was ermmmmm. .. yeah 25th sorry
– Leo
Dec 25, 2016 at 11:35
• Related challenges: Merry Christmas (and a Happy New Year), Christmas Countdown, and Is it Christmas? Dec 25, 2016 at 12:42
• Golfy Codemas! :) Dec 25, 2016 at 13:05
• No, it must be a crash. You can't quit the aplication
– Leo
Dec 25, 2016 at 13:25
• @PhiNotPi Those challenges are different. This is not asking for a countdown and does not involve waiting to give output
– Leo
Dec 25, 2016 at 14:04

## Pyke, 21 bytes

.dↄґ6C65h*325q/Al


Try it here!

     C65h*        -   multiply the day by the (current month + 1)
325q    -  ^ == 325
6         /   - 6 / ^
Al - ^.capwords()


Or 18 bytes noncompetitive.

.dↄґ6Cs6Y1q/Al


Exactly the same except for this section:

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


Try it here!

• This fails if it's October 30th, does it not? Dec 27, 2016 at 15:14
• @carusocomputing 30 * (10+1) = 330 not 325
– Blue
Dec 27, 2016 at 16:00

# JavaScript, 5553 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)

• How about .slice(6,10)=="c 25"? Dec 25, 2016 at 16:25
• @ConorO'Brien Thanks! That's smart :) Dec 25, 2016 at 16:28
• @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! Dec 25, 2016 at 18:30
• The result of Date() is completely implementation dependent. For example, I expect it to vary with the language and location of the machine. Dec 26, 2016 at 17:15
• @Oriol Then I will specify the browser in my answer Dec 26, 2016 at 17:18

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

• Does this crash on other days (it's supposed to)? Dec 25, 2016 at 13:29
• 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. Dec 25, 2016 at 13:43
• @ElPedro oops :D should have been 1:3, I copied my test code by accident Dec 25, 2016 at 16:55
• Picked up on that when I borrowed your gmtime() idea for my answer. Hope you don't mind :-) Dec 25, 2016 at 17:03

# 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];

• Can anyone golf 4 bytes off date(Lz)%1001-358? :D Dec 25, 2016 at 12:08
• Does this crash? Dec 25, 2016 at 21:26
• 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. Dec 25, 2016 at 22:34
• An alternative: eval((date(md)^TQZZ).'"Merry Christmas";'); (43 bytes) Dec 25, 2016 at 22:41
• @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. Jan 4, 2017 at 0:29

# Python 2, 6867 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]]

• Can't you save a byte by using a list instead of a tuple?
– Blue
Dec 25, 2016 at 13:56
• @muddyfish Thanks, good catch. Dec 25, 2016 at 13:58
• Nice one, my idea was 2 extra bytes :P Dec 25, 2016 at 15:29
• 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. Dec 25, 2016 at 15:40
• You can save 1 byte with: time.ctime()[6:10]!='c 25'
– Max
Dec 26, 2016 at 11:30

## 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

• Sorry about my little typo. I meant to say 25tg
– Leo
Dec 25, 2016 at 11:36
• This only works this year though! Dec 25, 2016 at 12:33
• @Erresen Ah right, silly mistake. Fixed now though. Dec 25, 2016 at 12:43

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

# Java, 200188 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!

• Welcome to PPCG! Nice first post, even though java isn't quite the shortest. Dec 26, 2016 at 20:17
• You 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... Dec 27, 2016 at 11:23
• @Daniel Gray, You are absolutely right, thanks! Dec 27, 2016 at 13:39
• Welcome! 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. Dec 27, 2016 at 16:55

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


## 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.

• What happens on days that aren't Christmas? Does it crash as it's supposed to? Dec 25, 2016 at 13:28
• @Erresen it does now. Dec 25, 2016 at 13:29

# 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 ;) .

• Also, x is short for duplicate and double :). Dec 26, 2016 at 17:32

# C# / CS Script 106100 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!
? "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"

• You can use $"{DateTime.Now:dM}"=="2512". dM is ambiguous, but not for "2512". – Kobi Dec 25, 2016 at 13:15 • @Kobi I can't use string interpolation for CS Script :( Dec 25, 2016 at 13:22 • You can if you use LinqPad (e.g. $"{DateTime.Now:dM}"=="2512"?"Merry Christmas":1/1-1+"" 55 bytes) =) Dec 25, 2016 at 23:13
• Why int i and notjust 1/0? Dec 26, 2016 at 3:54
• @Erresen Ah, my mistake. I didn't test thoroughly enough. Tweaked: $"{DateTime.Now:dM}"=="2512"?"Merry Christmas":"".Remove(1) (59 bytes) Dec 27, 2016 at 16:26 # 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. • Welcome to PPCG! Nice first post! Don't worry about the comment/answer thing, it doesn't matter too much. Dec 25, 2016 at 19:23 # bash + Unix utilities, 5149 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.

• 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. Dec 27, 2016 at 3:19 • @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. Dec 27, 2016 at 3:28 • 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. Dec 27, 2016 at 3:55 • Try replacing ${} with !- to beat me by one byte. I'll upvote you as you win. Dec 28, 2016 at 0:28
• @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). Dec 28, 2016 at 19:21 # 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. # 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.) ## 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. # 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 • It's meant to crash if it's not Christmas, this just exits normally. Dec 25, 2016 at 20:36 • You can save 2 bytes removing the colons --> '%d%m' == '2512' – Max Dec 26, 2016 at 11:17 • @Max OK, thanks for the tip. I hadn't used this function before, so I hadn't thought of doing that Dec 26, 2016 at 11:50 • save another 3 bytes with: time.ctime()[6:10]=='c 25' – Max Dec 26, 2016 at 12:01 # 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  ## C#.NET, 180172 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! }  • Can't you give the program a shorter class name? Dec 25, 2016 at 11:38 • You could remove some bytes by changing the "NotChristmasException" to something shorter. – Leo Dec 25, 2016 at 11:39 • @FishProHD The NotChristmasException is only in the ungolfed variant. Dec 25, 2016 at 11:40 • @KritixiLithos Thanks, changed that. Dec 25, 2016 at 11:41 • if(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) Dec 26, 2016 at 10:23 # Mathematica, 46 bytes If[Today[[1,2;;]]=={12,25},"Merry Christmas!"]  • Now saves 2 Bytes over Today Dec 28, 2016 at 14:50 • Also, you need a crash in the False outcome, so I think something like Quit[] or 1/0 should suffice. Dec 28, 2016 at 15:00 # 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. ## 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. ## 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. # 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. • The return is not necessary. Use i instead of (). Dec 26, 2016 at 21:06 ## 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. # 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) # 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! # bash command line, 4548 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. • Good idea, but this doesn't crash on days other than Christmas, like it's supposed to, does it? Dec 27, 2016 at 3:23 • It now gives an error on failure. Dec 27, 2016 at 4:03 • This 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. Dec 27, 2016 at 8:20
• @MitchellSpector: I found a 2 character sequence! Dec 28, 2016 at 0:27
• And now back to 48 by switching the logic so I can use ; instead of ||. Dec 28, 2016 at 0:43