Is it Christmas?

33

4

Challenge

Given that Christmas is:

  • December
  • Month 12
  • Day 25

Every year, determine today's date, and whether or not today is Christmas. If it is Christmas, you must print "It's Christmas". If it is not Christmas, you must somehow wait until Christmas and then print "It's Christmas".

Example

From this Stack Overflow Question

import time
while time.strftime("%b, %d", time.localtime()) != "Dec, 25":
    time.sleep(60)
print "It's Christmas"

Python in 115 Characters

Rules

Here are the rules:

  • Assume that the computer's clock is always right.
  • Your code must be able to be started at any time.
  • Your code must print "It's Christmas" on Christmas.
  • Looping is certainly not necessary, but once started your code should not stop until it has printed.
  • Shortest code wins.

Patrick Perini

Posted 2011-12-05T04:30:43.360

Reputation: 433

I thought the input is in Julian date before I read this post – Ming-Tang – 2011-12-21T09:51:51.837

Answers

18

Perl + Unix, 40 chars

1until`date`=~/c 25/;say"It's Christmas"

This is the same as J B's Perl solution, except that I save a few chars by using the external date command instead of Perl's localtime.

Ilmari Karonen

Posted 2011-12-05T04:30:43.360

Reputation: 19 513

144

Bash, 39

For those who just can't wait:

sudo date 12250000
echo It\'s Christmas

This follows all of the rules, especially the first one.

Joey Adams

Posted 2011-12-05T04:30:43.360

Reputation: 9 929

13You can save 5 characters if you're root. :D – Wug – 2012-10-08T21:11:03.517

11Clever. Not what I meant, but damned clever. – Patrick Perini – 2011-12-05T21:56:36.573

8“...and if the computer's clock isn't always right enough, make it.” Good show! – J B – 2011-12-06T08:49:18.963

29

Unix, 39 bytes

echo{,} "It\'s christmas"|at -t12252359

With help from Dennis, thanks for that.

user unknown

Posted 2011-12-05T04:30:43.360

Reputation: 4 210

2Using echo{,} "It\'s Christmas"|at -t12252359, this is shorter than the accepted answer. (The backslash is required by the way.) – Dennis – 2015-06-06T05:18:22.850

1@Dennis: Nice use of brace expansion. – Joey Adams – 2015-06-09T12:45:55.697

This violates »Looping is certainly not necessary, but once started your code should not stop until it has printed.«, though. – Joey – 2013-12-07T17:59:10.333

I don't understand your critique. Do you claim this is looping? That it stops before printing? – user unknown – 2013-12-07T19:30:46.880

18

PowerShell, 45 46 chars

for(;(date).date-ne'12/25'){}"It's Christmas"

It's certainly not very power-efficient, so a laptop battery might die before Christmas (reason to wish for a new one, maybe). But not sleeping is definitely shorter.

This is also locale-agnostic. And thanks to Jaykul for a nice trick in reducing this further.

Abusing the rules a bit, 45 chars

for(){"It's Christmas"*((date)-like'12/25*')}

This will print empty lines until it's Christmas, upon which it will print “It's Christmas”.

It ...

  • ... can be started at any time.
  • ... prints “It's Christmas” on Christmas. Several times. The whole day long. (The rules didn't say anything about how often it may be printed.)
  • ... does not print “It's Christmas” on not-Christmas (although it prints an empty line in that case; can be rectified by sacrificing another character, but then this gains nothing over the more sane solution above).
  • ... does not ever stop (not even after it has printed “It's Christmas” but definitely not before).

Joey

Posted 2011-12-05T04:30:43.360

Reputation: 12 260

You can remove the abuse now, it's unneeded. – Erik the Outgolfer – 2016-09-11T13:55:03.907

@EriktheGolfer: How so? It still offers an interesting alternative approach, even though it's not shorter. – Joey – 2016-09-11T14:35:14.617

The "abusive" script could also use -match, and do without the wildcard, for no gain/loss in characters. – Iszi – 2013-12-07T07:38:53.813

2for(;(date).date-ne"12/25"){}"It's Christmas" # 45 chars – Jaykul – 2011-12-06T06:32:52.417

Jaykul: Thanks ... that's something I never would have thought to be working. – Joey – 2011-12-06T09:54:55.447

13

Python (36 chars)

In the spirit of abusing the rules:

  • Definitely prints "It's Christmas" on Christmas

  • If it is not Christmas, pass the time by printing "It's Christmas"

    while True:
        print "It's Christmas"
    

Trying

Posted 2011-12-05T04:30:43.360

Reputation: 269

229 bytes: while 1:print"It's Christmas". – Erik the Outgolfer – 2016-09-11T13:56:28.110

11

PostScript, 90

(%Calendar%)currentdevparams begin{Month 12 eq Day 25 eq and{exit}if}loop(It's Christmas)=

Don't run on a printer, it doesn't print a page, and it will only DoS your printer until Christmas day. Then again, getting your printer back would be a nice present.

MrMRDubya

Posted 2011-12-05T04:30:43.360

Reputation: 171

4

Don't forget to tape a sign to the printer saying: DO NOT KILL JOB UNTIL CHRISTMAS!

– Joey Adams – 2011-12-06T16:58:23.887

I guess most printers won't even have a working hardware clock as that's an optional feature. Very nice, though :) – Joey – 2011-12-07T09:38:32.210

7

Mathematica, 47

While[Date[][[2;;3]]!={12,25}];"It's Christmas"

Mr.Wizard

Posted 2011-12-05T04:30:43.360

Reputation: 2 481

5

R (47)

while(!grepl("c 25",date())){};"It's Christmas"

zx8754

Posted 2011-12-05T04:30:43.360

Reputation: 150

1while(!grepl("c 25",date()))0;"It's Christmas" is 1 byte shorter. – Robin Ryder – 2020-01-09T11:23:10.190

5

Perl, 44 45

perl -E'1until localtime=~/c 25/;say"It's Christmas"'

Wouldn't GMT time be sufficient? (3 characters off ;-)

J B

Posted 2011-12-05T04:30:43.360

Reputation: 9 638

1until localtime=~/c 25/; would save you one char. :) – Ilmari Karonen – 2011-12-05T15:33:00.037

I thought I'd already tried that and it failed, but it turns out I actually forgot -E at the time. Thanks! – J B – 2011-12-05T15:49:21.473

No problem. (Ps. I just posted a version of your solution using backticks instead of localtime below. Feel free to steal it if you like, but I felt the extra dependency justified a separate answer.) – Ilmari Karonen – 2011-12-05T15:59:33.550

Naaaw, shame's on me for not thinking of it again. The separate answer is perfectly justified IMO (and upvoted).

– J B – 2011-12-06T08:54:17.240

5

Perl, 45

{localtime=~/c 25/&&die"It's Christmas";redo}

Perl, 44

using ternary operator (Thanks to Ilmari Karonen).

{localtime=~/c 25/?say"It's Christmas":redo}

Toto

Posted 2011-12-05T04:30:43.360

Reputation: 909

? : instead of && ; would save you one char too. (And I'd use say instead of die for prettier output.) – Ilmari Karonen – 2011-12-05T15:35:03.750

@Ilmari Karonen: thanks. But by using say instead of die, the script never finish. – Toto – 2011-12-05T15:43:35.257

It will, if you use the ternary operator. – Ilmari Karonen – 2011-12-05T15:49:21.823

@Ilmari Karonen: yes, of course. May be i'm too tired !!! – Toto – 2011-12-05T16:01:54.510

5

Javascript, 51 chars

It's a CPU killer:

while(!/c 25/.test(Date()));alert("It's Christmas")

David Murdoch

Posted 2011-12-05T04:30:43.360

Reputation: 260

4

I wanted to do this without parsing strings. Subsequently, there's a lot of magic numbers in my code.

I did some approximation to account for leap years. No one said that it had to print it out right on 00:00:00, Dec. 25!

Perl, 80 69 57 characters

{(time-30931200)%31557600<86399?die"It's Christmas":redo}

Edited for more concise looping!

Ben Richards

Posted 2011-12-05T04:30:43.360

Reputation: 291

3

Python, 66 68

import time
while'c 25'not in time.ctime():1
print"It's Christmas"

Steven Rumbalski

Posted 2011-12-05T04:30:43.360

Reputation: 1 353

That 1 at the end of the second line looks quite suspicious to me. :P – cjfaure – 2014-01-07T15:10:30.253

@Trimsty: The 1 provides a body for the while-loop. It's basically a busy wait until December 25. It has the similar effect to while 1:if'c 25'in time.asctime():break. – Steven Rumbalski – 2014-01-07T15:39:02.383

Ah, okay, thanks for clearing that up. – cjfaure – 2014-01-08T08:02:56.223

I think time.ctime() would do. – gnibbler – 2014-02-12T06:14:18.853

@gnibbler: Indeed it would. Nice catch. – Steven Rumbalski – 2014-02-12T15:41:39.930

3

TI-BASIC, 42 38

Repeat 769=sum(getDate²,2
End
"It's Christmas

Expects the date format to be YYYY/MM/DD.

getDate creates a three-element list {year,month,day}; only on Christmas is month^2 + day^2 equal to 769.

23 bytes are used for the string because lowercase letters are two bytes each, except for i which is displayed as the imaginary unit token.

lirtosiast

Posted 2011-12-05T04:30:43.360

Reputation: 20 331

2

PHP, 40 bytes

<?while(date(dm)-1225);?>It´s Christmas;

Loop until 25th of December; then exit to plain mode and print.

Run with default settings (don´t display notices).

Titus

Posted 2011-12-05T04:30:43.360

Reputation: 13 814

2

8086 machine code, 33 bytes

00000000  b4 2a cd 21 81 fa 19 0c  75 f6 b4 09 ba 12 01 cd  |.*.!....u.......|
00000010  21 c3 49 74 27 73 20 43  68 72 69 73 74 6d 61 73  |!.It's Christmas|
00000020  24                                                |$|
00000021

user5434231

Posted 2011-12-05T04:30:43.360

Reputation: 1 576

2

Batch file, 68 chars

:l
@date/t|findstr/c:"-12-25">nul&&echo It's Christmas&&exit
@goto l

Not usable interactively, as it kills the session. Solving that would require 5 more characters.

Also locale-sensitive. This works on my locale which uses ISO 8601 date format.

But hey, it's a batch file (by most not even regarded as a programming language). And shorter than Javascript (and on par with Python).

Joey

Posted 2011-12-05T04:30:43.360

Reputation: 12 260

2

Groovy, 55

while(!new Date()==~/.*c 25.*/);
println"It's Christmas"

Think it works, but still waiting for output.

Armand

Posted 2011-12-05T04:30:43.360

Reputation: 499

If Groovy's regexps are anything like in most other languages, those .* are entirely unnecessary. (Ps. You can test it by waiting for Dec 5 instead of 25.) – Ilmari Karonen – 2011-12-05T18:54:08.880

1Ilmari, Groovy is a JVM language and Java's regexes are anchored by default. – Joey – 2011-12-05T19:19:34.827

1Ilmari, I'd check but my program is still running – Armand – 2011-12-06T16:56:55.870

2

Ruby, 53

until Time.now.to_s=~/c 25/
end
puts"It's Christmas!"

Steven Rumbalski

Posted 2011-12-05T04:30:43.360

Reputation: 1 353

2

(pdf)eTeX - 180 chars only December 1-25.

\lccode`m`~\let\e\expandafter\def~{\ifdim900pt<\pdfelapsedtime
sp\pdfresettimer\else\e~\fi}\lowercase\e{\e\scantokens\e
{\romannumeral\numexpr (25 - \day)*96000}}It's Christmas!\bye

TeX only has a way to access the date when the program starts, and the time elapsed since the start, capped at 32768 seconds, so I need to compute the number of seconds to wait, and for each second do a loop which waits for the elapsed time to reach 1s and reset the time. (Precisely, I'm doing blocks of 900 seconds.)

Working for any month requires more work: 355 chars.

\lccode`m=`~\let\o\or\let\y\year\let\n\numexpr\let\e\expandafter
\def\b#1{\ifnum#1=\n(#1/4)*4\relax+1\fi}\def~{\ifdim
900pt<\pdfelapsedtime sp\pdfresettimer\else\e~\fi}\lowercase
\e{\e\scantokens\e{\romannumeral\n(25-\day+\ifcase\month\o334\b\y
\o303\b\y\o275\o244\o214\o183\o153\o122\o91\o61\o30\o0\ifnum25<\day
365\b{\n\y+1}\fi\fi)*96000}}It's Christmas!\bye

Bruno Le Floch

Posted 2011-12-05T04:30:43.360

Reputation: 1 181

2

MySQL, 180 chars

Because what are you using your database engine for, anyway?

DELIMITER $$
CREATE FUNCTION c() RETURNS CHAR(14) BEGIN a: LOOP IF DAY(NOW())=25 && MONTH(NOW())=12 THEN RETURN 'It\'s Christmas'; END IF; END LOOP a; END$$
DELIMITER ;
SELECT c();

Not very competitive lengthwise, but hey, it's doable!

TehShrike

Posted 2011-12-05T04:30:43.360

Reputation: 995

Try DELIMITER /, RETURNS TEXT and CURDATE()LIKE'%12-25'; and try to remove some whitespace. – Titus – 2017-04-16T23:24:54.710

1

Japt, 27 bytes (non-competing)

Ks f"c 25" ?`It's CËItµs`:P

To test against today's date : Replace c 25 with this month's last letter (shorthand) + space + day of the month. Feb 02 == b 02

Try it online! Non-competing because Japt is far newer than this challenge.

Oliver

Posted 2011-12-05T04:30:43.360

Reputation: 7 160

1

VBA, 58 Bytes

Anonymous VBE immediates window function that takes no input and runs until it's Christmas day, at which time it outputs It's Christmas to the VBE immediates window.

While Left(Now,5)<>"12/25":DoEvents:Wend:?"It's Christmas"

Taylor Scott

Posted 2011-12-05T04:30:43.360

Reputation: 6 709

1

SQL*Plus + PL/SQL - 100

EXEC LOOP EXIT WHEN TO_CHAR(SYSDATE,'DDMM')='2512';END LOOP;DBMS_OUTPUT.put_line('It''s Christmas');
  • Assuming SERVEROUTPUT ON
  • Shorter then the MySql solution (eat that, MySql!)
  • Too late for last year, but in time for this year
  • Tried DBMS_OUTPUT.put instead of DBMS_OUTPUT.put_line but that doesn't print anything.

SQB

Posted 2011-12-05T04:30:43.360

Reputation: 681

1

C# (126)

using System;class P{static void Main(){while(DateTime.Now.Date.ToString("Md")!="1225");Console.WriteLine("It's Christmas");}}

Nicer for your battery:

C# (163)

using s=System;class P{static void Main(){s.Threading.Thread.Sleep(s.DateTime.ParseExact("1225","Md",null)-s.DateTime.Now);s.Console.WriteLine("It's Christmas");}}

edit

The second ("nicer for your battery") version does have a bit of an issue dec. 26th to dec. 31st I just thought of :P

Both versions can probably be shortened a bit more.

RobIII

Posted 2011-12-05T04:30:43.360

Reputation: 397

1

Javascript, 93 89 78 77 chars

function x(){Date().match("c 25")?alert("It's Christmas"):setTimeout(x,1)}x()

JiminP

Posted 2011-12-05T04:30:43.360

Reputation: 3 264

Why setInterval to 1? setInveral to 1000*60*60*24 and it both won't make the process suffer and will notify only once on christmas. – George Mauer – 2014-02-12T20:24:23.647

@Joey Thanks! I forgot about that. – JiminP – 2011-12-05T09:52:31.190

2Another non-blocking version: setInterval('/c 25/.test(Date())&&alert("It\'s Christmas")',9) at 61 chars ... the only drawback is that it will alert() all day on Christmas. – David Murdoch – 2011-12-06T03:14:09.357

1

D, 130

import std.datetime,std.stdio;
main(){
do{
auto t = Clock.currTime();
}while(t.month!=12||t.day!=25);
writeln("It's Christmas");
}

ratchet freak

Posted 2011-12-05T04:30:43.360

Reputation: 1 334

You can probably save two characters in the assignment. And a few more by reducing the number of lines. – Joey – 2011-12-05T16:28:47.983

I can also save some by using t.month^12|t.day^25 (if I get my priorities right) – ratchet freak – 2011-12-05T18:38:12.530

1

Q, 63 chars

system"t 1000";.z.ts:{$["12.25"~-5#-3!.z.d;1"It's Christmas";]}

will work for christmas day on every year

tmartin

Posted 2011-12-05T04:30:43.360

Reputation: 3 917

0

SmileBASIC, 49 47 bytes

DTREAD OUT,M,D?"It's Christmas"*(M/D==.48)EXEC.

month/day will be 0.48 on December 25th.

12Me21

Posted 2011-12-05T04:30:43.360

Reputation: 6 110

0

PHP - 49 Characters

I got this quite short, so yeah.

<?while(date("dm")!="2512");echo"It's Christmas";

EDIT: Whoops, I printed something else than It's Christmas x3

cjfaure

Posted 2011-12-05T04:30:43.360

Reputation: 4 213

0

Rebol (53 chars)

wait difference 25-Dec-14 now
print "It's Christmas"

Of course the above will only wait till Xmas 2014 :)

Here's a version that will wait for next Xmas day:

next-xmas: does [
    d: now
    make date! reduce [25 12 either all [d/month = 12 d/day > 25][d/year + 1][d/year]]
]

wait difference next-xmas now
print "It's Christmas"

draegtun

Posted 2011-12-05T04:30:43.360

Reputation: 1 592

0

Befunge-98 (36 chars)

Requires a Unicode-capable interpreter (' is used for a literal 65536 and 'ఙ for 3097):

aa+y'%'ఙ-!#v_
s Christmas"<@,kd"It'

Explanation:

  • Use y with an argument of 20 to get the date field (aa+y)
  • Mask off the month & day portion by reducing mod-65536 ('%)
  • Subtract 3097 (= month * 256 + day) ('ఙ-)
  • If zero, print the string (abuses edge wrapping)
  • Otherwise repeat

TypeIA

Posted 2011-12-05T04:30:43.360

Reputation: 241

1Since default code-golf scoring is now in bytes, this should be at least 39 due to the multibyte characters. – lirtosiast – 2015-06-09T01:55:01.150

0

J, 54

'It''s Christmas'[(-^:(3 :'-.12 25-:1 2{6!:0''''')^:_)1

Eelvex

Posted 2011-12-05T04:30:43.360

Reputation: 5 204

0

bash-n-date: 69 chars:

sleep $(($(date -d"12/25" +%s)-$(date +%s))) && echo "It's X-Ray    "

But it will fail on Dec. 26th to Dec. 31th.

user unknown

Posted 2011-12-05T04:30:43.360

Reputation: 4 210

0

Q (60)

 system"t 1000";.z.ts:{if[.z.d~2012.12.25;1"It’s Christmas"]}

sinedcm

Posted 2011-12-05T04:30:43.360

Reputation: 410

ockquote>

If it is not Christmas, you must somehow wait until Christmas and then print "It's Christmas".

– skeevey – 2012-03-07T13:55:00.277

My apologies, corrected to check every second if it's Christmas...so this will print "It's Christmas" 86,400 times every 25th December. Obviously you can alter this by increasing the timer, which is in milliseconds. – sinedcm – 2012-03-07T14:20:30.773

-2

Groovy - 88

new Timer().schedule({print"It's Christmas"}as TimerTask,Date.parse("yyddMM","112512"))

mohammad shamsi

Posted 2011-12-05T04:30:43.360

Reputation: 131

1Is all that whitespace necessary? – Joey – 2011-12-05T16:28:07.827

@Joey no, it was for the sake of readability. – mohammad shamsi – 2011-12-05T16:32:05.687

6Does it work every year? Don't think so. – user unknown – 2011-12-08T22:43:46.297