34
\$\begingroup\$

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.
\$\endgroup\$
1
  • \$\begingroup\$ I thought the input is in Julian date before I read this post \$\endgroup\$
    – Ming-Tang
    Dec 21, 2011 at 9:51

36 Answers 36

1
2
0
\$\begingroup\$

Q (60)

 system"t 1000";.z.ts:{if[.z.d~2012.12.25;1"It’s Christmas"]}
\$\endgroup\$
2
  • \$\begingroup\$ > If it is not Christmas, you must somehow wait until Christmas and then print "It's Christmas". \$\endgroup\$
    – skeevey
    Mar 7, 2012 at 13:55
  • \$\begingroup\$ 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. \$\endgroup\$
    – sinedcm
    Mar 7, 2012 at 14:20
0
\$\begingroup\$

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

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

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

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
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Since default code-golf scoring is now in bytes, this should be at least 39 due to the multibyte characters. \$\endgroup\$
    – lirtosiast
    Jun 9, 2015 at 1:55
0
\$\begingroup\$

J, 54

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

Groovy - 88

new Timer().schedule({print"It's Christmas"}as TimerTask,Date.parse("yyddMM","112512"))
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Is all that whitespace necessary? \$\endgroup\$
    – Joey
    Dec 5, 2011 at 16:28
  • \$\begingroup\$ @Joey no, it was for the sake of readability. \$\endgroup\$ Dec 5, 2011 at 16:32
  • 6
    \$\begingroup\$ Does it work every year? Don't think so. \$\endgroup\$ Dec 8, 2011 at 22:43
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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