35
\$\begingroup\$

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!

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

28 Answers 28

8
\$\begingroup\$

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!

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

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)

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

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

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

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

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

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

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!

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

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)
\$\endgroup\$
3
\$\begingroup\$

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
[email protected]|     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.

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

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

\$\endgroup\$
1
  • \$\begingroup\$ Also, x is short for duplicate and double :). \$\endgroup\$
    – Adnan
    Dec 26, 2016 at 17:32
3
\$\begingroup\$

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"

\$\endgroup\$
8
  • 1
    \$\begingroup\$ You can use $"{DateTime.Now:dM}"=="2512". dM is ambiguous, but not for "2512". \$\endgroup\$
    – Kobi
    Dec 25, 2016 at 13:15
  • \$\begingroup\$ @Kobi I can't use string interpolation for CS Script :( \$\endgroup\$
    – Erresen
    Dec 25, 2016 at 13:22
  • 1
    \$\begingroup\$ You can if you use LinqPad (e.g. $"{DateTime.Now:dM}"=="2512"?"Merry Christmas":1/1-1+"" 55 bytes) =) \$\endgroup\$
    – Kenneth K.
    Dec 25, 2016 at 23:13
  • \$\begingroup\$ Why int i and notjust 1/0? \$\endgroup\$ Dec 26, 2016 at 3:54
  • 1
    \$\begingroup\$ @Erresen Ah, my mistake. I didn't test thoroughly enough. Tweaked: $"{DateTime.Now:dM}"=="2512"?"Merry Christmas":"".Remove(1) (59 bytes) \$\endgroup\$
    – Kenneth K.
    Dec 27, 2016 at 16:26
2
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to PPCG! Nice first post! Don't worry about the comment/answer thing, it doesn't matter too much. \$\endgroup\$
    – Riker
    Dec 25, 2016 at 19:23
2
\$\begingroup\$

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.

\$\endgroup\$
8
  • \$\begingroup\$ 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. \$\endgroup\$
    – Ken Y-N
    Dec 27, 2016 at 3:19
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ Dec 27, 2016 at 3:28
  • \$\begingroup\$ 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. \$\endgroup\$
    – Ken Y-N
    Dec 27, 2016 at 3:55
  • \$\begingroup\$ Try replacing ${} with !- to beat me by one byte. I'll upvote you as you win. \$\endgroup\$
    – Ken Y-N
    Dec 28, 2016 at 0:28
  • 1
    \$\begingroup\$ @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). \$\endgroup\$ Dec 28, 2016 at 19:21
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
4
  • 1
    \$\begingroup\$ It's meant to crash if it's not Christmas, this just exits normally. \$\endgroup\$
    – FlipTack
    Dec 25, 2016 at 20:36
  • \$\begingroup\$ You can save 2 bytes removing the colons --> '%d%m' == '2512' \$\endgroup\$
    – Max
    Dec 26, 2016 at 11:17
  • \$\begingroup\$ @Max OK, thanks for the tip. I hadn't used this function before, so I hadn't thought of doing that \$\endgroup\$
    – AvahW
    Dec 26, 2016 at 11:50
  • \$\begingroup\$ save another 3 bytes with: time.ctime()[6:10]=='c 25' \$\endgroup\$
    – Max
    Dec 26, 2016 at 12:01
1
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

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!
}
\$\endgroup\$
11
  • \$\begingroup\$ Can't you give the program a shorter class name? \$\endgroup\$
    – user41805
    Dec 25, 2016 at 11:38
  • \$\begingroup\$ You could remove some bytes by changing the "NotChristmasException" to something shorter. \$\endgroup\$
    – Leo
    Dec 25, 2016 at 11:39
  • \$\begingroup\$ @FishProHD The NotChristmasException is only in the ungolfed variant. \$\endgroup\$
    – devRicher
    Dec 25, 2016 at 11:40
  • \$\begingroup\$ @KritixiLithos Thanks, changed that. \$\endgroup\$
    – devRicher
    Dec 25, 2016 at 11:41
  • 1
    \$\begingroup\$ 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) \$\endgroup\$ Dec 26, 2016 at 10:23
0
\$\begingroup\$

Mathematica, 46 bytes

If[Today[[1,2;;]]=={12,25},"Merry Christmas!"]
\$\endgroup\$
2
  • \$\begingroup\$ Now saves 2 Bytes over Today \$\endgroup\$ Dec 28, 2016 at 14:50
  • \$\begingroup\$ Also, you need a crash in the False outcome, so I think something like Quit[] or 1/0 should suffice. \$\endgroup\$ Dec 28, 2016 at 15:00
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ The return is not necessary. Use i instead of (). \$\endgroup\$
    – raznagul
    Dec 26, 2016 at 21:06
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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)

\$\endgroup\$
0
\$\begingroup\$

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!

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
8
  • \$\begingroup\$ Good idea, but this doesn't crash on days other than Christmas, like it's supposed to, does it? \$\endgroup\$ Dec 27, 2016 at 3:23
  • \$\begingroup\$ It now gives an error on failure. \$\endgroup\$
    – Ken Y-N
    Dec 27, 2016 at 4:03
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Dec 27, 2016 at 8:20
  • \$\begingroup\$ @MitchellSpector: I found a 2 character sequence! \$\endgroup\$
    – Ken Y-N
    Dec 28, 2016 at 0:27
  • \$\begingroup\$ And now back to 48 by switching the logic so I can use ; instead of ||. \$\endgroup\$
    – Ken Y-N
    Dec 28, 2016 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.