Encode the date in Christmas Eve format

51

1

The day this post was published was Christmas Eve. Tomorrow will be Christmas. Yesterday was Christmas Eve Eve. In two days it will be

Christmas Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve

.

Your job is to take the date the program is run and encode it in Christmas Eve format.

  • If your program is run on Christmas, it should output the string "Christmas".
  • If your program is not run on Christmas, it should output the string "Christmas", followed by the string " Eve" repeated n times, where n is the number of days until Christmas.
    • Note that this must be based on the next Christmas. For example, if the day is April 26, 2019, you must do your calculation based on December 25, 2019, not any other Christmas.
    • Remember to count leap days.
  • Christmas is December 25th of every year.

This is , so the shortest code wins! Note though that the goal is not to find the shortest program in any language, but to find the shortest program in every particular language. For example, if you find the shortest C++ program, then it wins this contest for C++, even if someone finds a shorter program in Python.

PyRulez

Posted 2018-12-24T23:10:06.843

Reputation: 6 547

7Somehow I knew that this was going to be a PPCG challenge the moment I saw the cartoon - +1 from me – Black Owl Kai – 2018-12-24T23:36:07.603

@BlackOwlKai what cartoon? – PyRulez – 2018-12-24T23:37:09.923

25

A xkcd cartoon that was published today. https://imgs.xkcd.com/comics/christmas_eve_eve.png

– Black Owl Kai – 2018-12-24T23:38:27.923

7@BlackOwlKai LMBO I didn't even see that comic until your comment. I had already planned to post this, and was just waiting for Christmas Eve. Great minds think alike, I guess? – PyRulez – 2018-12-24T23:41:56.543

You should specify that you mean Dec 25 for "Christmas", unless you want submissions that use a local date or calendar. – Sparr – 2018-12-25T00:51:13.790

@Sparr fixed it – PyRulez – 2018-12-25T02:29:14.913

@tsh a quick search suggests that is true in all time zones. Since dates are complicated as it is, you may assume anything that is always true (i.e. you do not need to worry about hypotheticals). – PyRulez – 2018-12-25T02:44:07.310

So, is the program supposed to encode a given date, or produce output based on the date it's run? – Sean – 2018-12-25T02:58:25.740

@Sean oh, it produces output based on the day it runs. I'll fix the post. – PyRulez – 2018-12-25T02:59:46.810

Does case matter? Can we output all uppercase or all lowercase? – Shaggy – 2018-12-25T08:39:36.977

@Shaggy uhm, we'll say case matters, since the post didn't say otherwise. Too late to change it now. – PyRulez – 2018-12-25T13:53:38.280

What about the second holiday? It´s still Christmas on Decmber 26, isn´t it? – Titus – 2018-12-25T16:05:31.560

@Titus yes, but it is also Christmas Eve*364. – PyRulez – 2018-12-25T16:06:39.543

1Can the date be a parameter? – Olivier Grégoire – 2018-12-26T11:23:32.010

1@OlivierGrégoire uhm, I'll permit it iff the language does not have the ability to get the current date in another way. – PyRulez – 2018-12-26T14:53:42.453

1This may be nitpicking, but 25 December is not Christmas (there are, famously, twelve days to the holiday – or more, or fewer, depending on locality), but Christmas Day. It would make more sense to output Christmas Eve(ⁿ) for other days and then Christmas Day on 25 December. – Janus Bahs Jacquet – 2018-12-27T11:38:41.317

1@JanusBahsJacquet okay, I'll edit the question and flag all the current answers as being outdated. On a serious note, I'll keep that in mind in the future, but it's kinda hard to fix now. – PyRulez – 2018-12-27T20:26:07.523

We can ignore leap seconds, right? – ASCII-only – 2018-12-28T00:38:38.813

@ASCII-only I already told someone else not to, so probably not. – PyRulez – 2018-12-28T04:42:48.723

https://xkcd.com/2089/ – MilkyWay90 – 2019-01-03T17:00:19.047

Answers

54

SmileBASIC, 73 71 67 bytes

?"Christmas";
@L?" Eve"*(D!=P);
P=D
DTREAD OUT,M,D
IF M/D-.48GOTO@L

The program prints "Christmas", then prints " Eve" every time a day passes, until it is December 25th. (12/25 = 0.48)
May take up to a year to run.

12Me21

Posted 2018-12-24T23:10:06.843

Reputation: 6 110

8pure genius ... – FlipTack – 2018-12-25T11:43:14.857

8This made me Smile... – Neil – 2018-12-25T14:10:11.477

3Nice! One of my JavaScript solutions takes a similar approach. However, in JavaScript the wait time is just a best effort. How is SmileBASIC faring in this regard? – targumon – 2018-12-26T00:16:34.713

2The code runs continuously (until christmas) and detects the start of each day by checking the date to see if it has changed. I had another version (which was the same length) that used delays instead, but I wasn't sure how reliable it would be. – 12Me21 – 2018-12-26T00:34:18.240

4@12Me21 that would obviously fail due to leap seconds, this version looks much better. – Rɪᴋᴇʀ – 2018-12-26T16:08:19.100

1The system that this runs on doesn't have leap seconds (or even daylight savings time; you have to adjust the clock manually). A bigger issue is that the delay function (WAIT) takes a time in frames which are close to 1/60 of a second (but really 1/59.834) and probably isn't as accurate as the clock. – 12Me21 – 2018-12-26T16:54:36.303

6+1 for thinking outside the box and making me laugh. – Tom – 2018-12-27T10:29:04.110

1Best laugh I've had in days +1! – JohnWells – 2019-01-07T00:08:05.393

24

Excel formula, 59 bytes

="Christmas"&REPT(" Eve",DATE(YEAR(NOW()+6),12,25)-TODAY())

Richard Crossley

Posted 2018-12-24T23:10:06.843

Reputation: 351

4I think YEAR(TODAY()+6) always returns the correct year, thus avoiding the condition. – Neil – 2018-12-25T19:32:45.970

Shouldn't it be > (instead of >=) ? – targumon – 2018-12-25T21:00:46.253

targumon, Yes, that outputs "Christmas" on it's own – Richard Crossley – 2018-12-26T00:13:29.923

Neil, that works nicely: ="Christmas"&REPT(" Eve",DATE(YEAR(TODAY()+6),12,25)-TODAY()) – Richard Crossley – 2018-12-26T00:21:42.837

3I think YEAR(NOW()+6) works as well with 2 less bytes. – Engineer Toast – 2018-12-26T20:01:51.187

Thanks Engineer Toast, good spot. – Richard Crossley – 2018-12-27T01:48:34.487

2I think ="Christmas"&REPT(" Eve",DATE(YEAR(NOW()+6),12,26)-NOW()) is even shorter and I believe it should work. – JeroendeK – 2018-12-27T14:02:42.330

(How does Excel formula get a byte count, what do you use?) – BruceWayne – 2018-12-27T19:22:19.260

Just counted the bytes used to express the formula in a text editor – Richard Crossley – 2018-12-27T23:16:44.390

1NOW() includes the time, so it won't be an integer and I'm not sure REPT would allow that. – 12Me21 – 2018-12-28T04:57:24.347

1@12Me21 REPT allows it, it floors the given number, which is why I changed the 25 to a 26. – JeroendeK – 2018-12-28T09:55:12.530

2but this does not give "Christmas" on Christmas day. Check ="Christmas"&REPT(" Eve",DATE(YEAR(DATE(2018,12,25)+6),12,26)-DATE(2018,12,25)) – Anthony – 2018-12-29T15:18:45.647

1Isn't this 59 bytes? – Downgoat – 2018-12-31T03:59:19.423

12

Perl 6, 61 47 bytes

say 'Christmas'~' Eve'x(Date.today...^{.month==12&&.day==25})

say 'Christmas'~' Eve'x(Date.today...^/12\-25/)

Try it online!

-14 bytes (!) thanks to Jo King

Date.today ...^ /12\-25/ is the sequence of dates starting today and ending the day before Christmas. (The regular expression /12\-25/ is matched against the string representation of the dates.) The string " Eve" is replicated a number of times equal to the length of that sequence, and is output after the string "Christmas".

Sean

Posted 2018-12-24T23:10:06.843

Reputation: 4 136

Could you do "month>11" to save a byte? – chrixbittinx – 2018-12-26T19:35:35.350

2Would /12.25/ work? – user41805 – 2018-12-27T07:49:33.837

2@Cowsquack no, because then it might match the year in dates like 12025-12-24 – Jo King – 2018-12-27T12:05:49.023

I think it's safe to assume that will never happen – 12Me21 – 2018-12-28T06:24:34.707

8

R, 112 106 72 bytes

Via @digEmAll and @J.Doe

x=Sys.Date()-1;cat('Christmas');while(!grepl('12-25',x<-x+1))cat(' Eve')

Try it online!

My original answer was prior to the clarification that the code was to take the date on which the code is run as input. It could be modified as above to save many bytes but I won't bother.

function(x,z=as.Date(paste0(strtoi(format(x,"%Y"))+0:1,"-12-25"))-x)cat("Christmas",rep("Eve",z[z>=0][1]))

Try it online!

Explanation: everyone's at church so I have time to do this. Extract the year, coerce to integer. Make vector of that year's Xmas and the next year's Xmas and subtract the input date to get a vector of two differences between the input date and those two Xmases.

Pick the non-negative one and cat "Christmas" with that many "Eves".

ngm

Posted 2018-12-24T23:10:06.843

Reputation: 3 974

You only use y once so you can just use it directly for 108 bytes. – Giuseppe – 2018-12-25T02:02:47.850

Also would z[z>=0][1] work instead of min? – Giuseppe – 2018-12-25T02:03:58.810

73 bytes. According to the last comment, the program must output the text based on the day it runs. Merry christmas BTW ! :D – digEmAll – 2018-12-25T10:16:07.933

1

Tweaked yours for 72 bytes, @digEmAll. Merry Christmas!

– J.Doe – 2018-12-25T11:34:16.583

8

Windows PowerShell, 67 64 63 bytes

for(;1225-'{0:Md}'-f(date|% *ys $i)){$i++}'Christmas'+' eve'*$i

Try it online!

Managed to shave off 3 bytes 4 bytes (thanks Cows quack) by using the -format operator instead of .ToString(), and then subtracting the date string from the numerical value 1225 instead of doing a comparison with -ne. The resulting integer will be interpreted as a boolean for the conditional where 0 (which will happen on Christmas) is interpreted as False (don't enter the loop), and any other value is interpreted as True (enter the loop).

Since the integer is on the left now, the date string will be converted to the integer and math will be done, as opposed to the previous version where the 1225 integer was converted to string for the comparison.

Original Version


Windows PowerShell, 67 bytes

for(;(date|% *ys $i|% tost* Md)-ne1225){$i++};'Christmas'+' eve'*$i

Try it online!

Using a for loop as a while loop basically, because it's shorter. In the loop condition we check the current date (date, a shortened form of Get-Date), piped to ForEach-Object's alias %, using the form that can invoke a method by wildcarded name; in this case the method is AddDays() on the DateTime object, and the value we give it is $i.

This gets piped to ForEach-Object again to invoke the ToString() method, with format string Md (month, then day, minimal digits since we don't care for what comes next). This string is then tested to see if it's not equal -ne to the number 1225, which will be converted to a string for the comparison, saving me the quotes.

This is why it doesn't matter that the months and days are single digits, it will never be ambiguous because there's no other day of the year that would stringify to 1225.

The loop continues until the string is 1225. At the beginning of the program, $i will be zero so it will be comparing today's date, and the loop will never execute, but for any other day $i gets incremented in the loop body, so that we will have a count of how many days until the next Christmas, automatically accounting for leap years and whether or not Christmas passed this year.

After the loop we just output the string Christmas concatenated with the result of multiplying the string eve times the value of $i (which, on Christmas day, will be 0, resulting in no eves).

briantist

Posted 2018-12-24T23:10:06.843

Reputation: 3 110

Apparently the ; after {$i++} is redundant? (also wow you took the lead over bash again) – user41805 – 2018-12-27T18:45:07.157

@Cowsquack nice! how did I not notice that?! – briantist – 2018-12-27T18:58:21.687

7

C# (Visual C# Interactive Compiler), 89 bytes

Write("Christmas");for(var t=DateTime.Now;$"{t:Md}"!="1225";t=t.AddDays(1))Write(" Eve");

Try it online!

-3 bytes thanks to @JeppeStigNielsen!

My strategy is pretty straightforward:

  1. Initialize a loop variable t to the current date
  2. Print Eve if t is not Christmas
  3. Add a day to t and repeat

I tried some fancier things, but this way required the fewest bytes.

dana

Posted 2018-12-24T23:10:06.843

Reputation: 2 541

...do you need to assign t to itself in the incrementor? I don't have the docs in front of me, but if not, you could save two bytes more. – Stackstuck – 2018-12-28T21:38:44.193

1oh, it's a struct. Of course it is. Nevermind. – Stackstuck – 2018-12-28T21:39:28.373

1You can substitute t.Month<12|t.Day!=25 with the shorter $"{t:Md}"!="1225". It uses an interpolated string and a custom DateTime formatting string. – Jeppe Stig Nielsen – 2018-12-28T23:34:16.907

6

T-SQL, 92 88 bytes

PRINT'Christmas'+REPLICATE(' Eve',DATEDIFF(D,GETDATE(),STR(YEAR(GETDATE()+6))+'-12-25'))

Edit: Saved 4 bytes thanks to @BradC.

Neil

Posted 2018-12-24T23:10:06.843

Reputation: 95 035

Nice work. Save 2 with PRINT'Christmas'+... and 2 more by using DATEDIFF(D, instead of DATEDIFF(DAY, – BradC – 2019-01-07T16:19:34.220

@BradC Nice, thanks! – Neil – 2019-01-07T16:54:13.940

5

APL (Dyalog Unicode), 76 63 bytesSBCS

Full program. Assumes ⎕IO←0 (zero-indexing).

⎕CY'dfns'
'Christmas',' Eve'⍴⍨4×12 25⍳⍨⍉2↑1↓⍉date(⍳366)+days⎕TS

Try it online!

⎕CY'dfns'copy in the dfns library

⎕TS current time stamp as [year,month,day,hour,min,sec,ms]
days[c] find the number of days[n] since 1899-12-31 00:00:00.000
(⍳366) add the first 366 integers (0…365) to that
date[c] find the dates[n] that correspond to those numbers (366×7 table; one column per unit)
 transpose (7×366 table; one row per unit)
1↓ drop one row (the years)
2↑ take the first two rows (months and days)
12 25⍳⍨ find the index of the first Christmas
 multiply that by four
' Eve'⍴⍨ use that to reshape the character list
'Christmas ', append that to this

[c] code of that function
[n] notes for that function

Adám

Posted 2018-12-24T23:10:06.843

Reputation: 37 779

5

Python 2, 111 103 bytes

from datetime import*
d=date.today()
print"Christmas"+" Eve"*(date((d+timedelta(6)).year,12,25)-d).days

Try it online!

Update inspired by Richard Crossley's answer.

Explanation:

from datetime import*
# get today as a date, so we don't have to worry about rounding errors due to time
d=date.today()
                              # get the year of the Christmas to compare to
                              # if the current date is after this year's Christmas, the 6 day offset will give the next year
                              # otherwise, returns this year
                              (d+timedelta(6)).year
                         # next Christmas minus the current date
                         date(.....................,12,25)-d
# Christmas, plus (number of days until next Christmas) " Eve"s
print"Christmas"+" Eve"*(...................................).days

Triggernometry

Posted 2018-12-24T23:10:06.843

Reputation: 765

4

Ruby, 80 bytes

require'date'
t=Date.today
puts'Christmas'+' Eve'*(Date.new((t+6).year,12,25)-t)

Try it online!

Thanks to tsh for his idea

iBug

Posted 2018-12-24T23:10:06.843

Reputation: 2 477

77 bytes (i.e., save 3 bytes) by replacing puts with p: Try It Online link

– Spencer D – 2018-12-30T06:57:01.443

4

PHP, 61 bytes

Christmas<?for($t=time();date(md,$t+=86400)-1226;)echo" Eve";

Run with -n or try it online.

Titus

Posted 2018-12-24T23:10:06.843

Reputation: 13 814

4

JavaScript, 135 131 121 92 88 bytes

My first (naïve) solution (135b):

t=new Date();n=new Date();n.setMonth(11);n.setDate(25);'Christmas'+' Eve'.repeat((n>=t?n-t:(n.setFullYear(n.getFullYear()+1)-t))/864e5)

It sets 2 dates: now and Xmas of this year. If the latter hasn't passed yet, it just diffs them, if it has passed, diffs to next year's Xmas. Uses either diffs for the number of repeats.

(Trying to) Think Outside the Box (131b):

i=0;f=_=>{t=new Date();if(t.getMonth()!=11||t.getDate()!=25){i++;setTimeout(f,864e5)}else{alert('Christmas'+' Eve'.repeat(i))}};f()

The challange specifies WHICH output is required when running the program on a given day, but doesn't specify WHEN to return it...

This will just 'sleep' for a day, increment a counter by 1, and repeat till it's Xmas in order to give the output.

Since JavaScript doesn't guarantee the 'sleep' time, the actual result might be off.

It is also ugly for using the alert function, which means wer'e actually not dealing with pure JavaScript, but with browser APIs as well (we can use console.log at the cost of 6 extra bytes).

A better approach (121b):

t=new Date();i=0;while(t.getMonth()!=11||t.getDate()!=25){t=new Date(t.valueOf()+864e5);i++};'Christmas'+' Eve'.repeat(i)

Starting from today, increment the date by a day until it's Xmas, then use that loop's counter for the number of repeats required.

Improving (including going through a minifier and using 12Me21's trick to shave extra 5b) (92b):

for(s='Christmas',t=new Date;t.getMonth()/t.getDate()-.44;)t=new Date(t*1+864e5),s+=' Eve';s

Final touches (88b):

for(s='Christmas',t=new Date;t.getMonth()/(d=t.getDate())-.44;t.setDate(d+1))s+=' Eve';s
  • For all of the above, REPL is assumed.
  • See Vadim's submission - much better than mine!

targumon

Posted 2018-12-24T23:10:06.843

Reputation: 155

1I think you can use t.getMonth()/t.getDate-.48 to check if date is not december 25th – 12Me21 – 2018-12-26T00:50:40.527

Ooh, that's sneaky! In JavaScript it actually should be .44 because the month is zero-based (but the numerator and denominator are still coprime so the fraction is unique and the idea still holds) Thanks! – targumon – 2018-12-26T01:11:06.437

1Welcome to the site! You can use a 4 space indent to make your code blocks look better. – Post Rock Garf Hunter – 2018-12-26T03:51:45.853

1Welcome to PPCG! – Shaggy – 2018-12-26T11:47:17.130

198, print is needed since this is a program not a function, unless 1. you turn it into a lambda or 2. you state that you're using a REPL – ASCII-only – 2018-12-28T01:28:48.820

1t=new Date(+t+864e5) is 1 byte shorter. – Andrew Svietlichnyy – 2018-12-29T19:16:01.950

1Assigning Date to a variable saves couple of bytes too: x=Date;...t=new x and so on – Pete TNT – 2018-12-30T19:29:27.270

@ASCII-only Actually print is not JS (it's browser API, so won't work on Node.js for example) but you're right! I meant REPL and otherwise we incur 13bytes of console.log(). – targumon – 2018-12-31T23:17:59.047

@AndrewSvietlichnyy - Nice!

@PeteTNT - Not quite... I used Date only twice, so replacing each one with x saves a total of 6bytes. But x=Date; costs us 7bytes...

Anyway, I found another shortcut (see my recent edit). Also see solution by Vadim which is better than mine by 12.5%! – targumon – 2018-12-31T23:19:39.990

@targumon it's spidermonkey-specific, not browser – ASCII-only – 2018-12-31T23:28:15.260

spidermonkey is a browser ;-) – targumon – 2018-12-31T23:46:19.590

3

Python 2, 128 bytes / Python 3, 130 bytes

of course, two less bytes with Python 2

from datetime import date as D
T=D.today()
Y=T.year
a=(D(Y,12,25)-T).days
print("Christmas"+" Eve"*[a,(D(Y+1,12,25)-T).days][a<0])

iBug

Posted 2018-12-24T23:10:06.843

Reputation: 2 477

1105 bytes – tsh – 2018-12-25T13:00:14.903

@tsh That's an amazing approach! – iBug – 2018-12-25T13:18:37.237

1Python 2 doesn't need a space after print so it's 128 bytes – NieDzejkob – 2018-12-28T12:48:31.057

3-2 bytes by implementing as D by yourself – NieDzejkob – 2018-12-28T13:05:52.040

3

Bash +GNU date, 72 73 bytes

for((d=0;1`date +%d%m -d$d\day`-12512;d++));{ x+=\ Eve;};echo Christmas$x
  • one byte saved replacing != with -
  • another removing extra space
  • fix -3 bytes d=0, because date -dday is date+1 and doesn't work on 25/12

Try it online

Nahuel Fouilleul

Posted 2018-12-24T23:10:06.843

Reputation: 5 582

Hmmm, why does =~ not work in the for-loop conditional? – user41805 – 2018-12-26T19:14:59.193

because the for loop condition is an arithmetic expression, words are coerced to integer also number starting with 0 are assumed in octal, that's why 1 is prepended – Nahuel Fouilleul – 2018-12-27T08:04:00.477

3

Bash, 68 65 61 bytes

Golfed 4 bytes thanks to Nahuel Fouilleul by using `` command substitution and eval in place of sed e and xargs

echo Christmas `eval date\ -d{0..366}day\;|sed /c.25/Q\;cEve`

Try it online!

Inside the `` command substitution, we have

eval run the following string as shell commands

  • date\ -d{0..366}day\; under brace expansion of {0..366}, this results in the string date -d0day; date -d1day; date -d2day; ... date -d366day;, each command in this string computing the date between 0 and 366 days from present resulting in output of the format Wed Dec 26 18:22:33 UTC 2018, with each in its own line

|sed upon which, call the following sed commands

  • /c.25/Q if the regex /c.25/ is matched, Quit without printing

  • \;cEve otherwise change the line to Eve

All the required number of Eves are produced each on its own line. This output is captured in ``, and is subject to word splitting where words are split on newlines. Each word is fed as an argument to echo.

echo Christmas ...

Each argument to echo is printed by being separated by spaces, resulting in the desired output.

user41805

Posted 2018-12-24T23:10:06.843

Reputation: 16 320

There's nothing really bash-specific about this solution. It requires GNU date, sed and seq though. – Kusalananda – 2018-12-27T21:00:07.330

-4 bytes – Nahuel Fouilleul – 2018-12-28T09:12:29.423

@NahuelFouilleul Thanks, nice trick of using backtick command substitution to avoid xargs and using eval to skip out on seq – user41805 – 2019-07-21T18:03:02.950

3

VBA (Excel), 108 bytes

Copy in a blank module. Prints to the Immediate window:

Sub X:s="Christmas":d=Now:For t=1 To (DateSerial(Year(d+6),12,25)-d):s=s &" Eve":Next:Debug.Print s:End Sub

Note: Using : instead of line breaks saves two bytes per line.

Notice that the VBA editor will insert additional spaces between keywords, operators, etc... and parenthesis after the Sub definition, but if you copy and paste this code it will work (I couldn't get rid of that space before the &).

Not bad for VBA (for once).

Barranka

Posted 2018-12-24T23:10:06.843

Reputation: 422

1*Christmas :| – ASCII-only – 2018-12-26T23:47:30.690

@ASCII-only: removing the space before the & throws an error – Barranka – 2018-12-26T23:49:41.740

-1 bytes. Thanks to @ASCII-only for catching the typo – Barranka – 2018-12-27T00:06:10.253

1You can cut this down to 71 chars by converting it to an immediate window function and removing the temporary variable for now. When you do that, it should look something like ?"Christmas";:For i=1To DateSerial(Year(Now+6),12,25)-Now:?" Eve";:Next – Taylor Scott – 2019-02-13T21:54:18.897

2

Groovy, 66 bytes

d=[]as Date
print'Christmas'+' Eve'*(new Date((d+6).year,11,25)-d)

Try it online!

Courtesy of @ASCII-only

bdkosher

Posted 2018-12-24T23:10:06.843

Reputation: 121

You need to print it out since this is a full program not a function – ASCII-only – 2018-12-27T23:25:34.450

ockquote>

Chistmas :/

– ASCII-only – 2018-12-27T23:32:13.770

fixed, 149 – ASCII-only – 2018-12-27T23:36:27.170

123 – ASCII-only – 2018-12-27T23:55:05.417

taking your first one and using Groovy 2.5 slims it down to 115.

– bdkosher – 2018-12-28T00:01:03.613

We'll just need to ask Dennis to update Groovy and we'll get 112 maybe? Hmmmmm

– ASCII-only – 2018-12-28T00:03:21.280

nevermind, if we use crusty java.util.Date we can get it down to 76

– bdkosher – 2018-12-28T00:05:14.910

You mean 73

– ASCII-only – 2018-12-28T00:07:09.067

What hackery does Groovy use to make that work? Looks like Scala doesn't have a lot of it – ASCII-only – 2018-12-28T00:13:20.913

Seems like we're not going to get any lower for a while :P you might want to update your answer (protip: in the topbar of TIO, there's a button which opens a page that generates all kinds of formatted links for you, including one that is formatted for PPCG: esc + s + g. If you want to keep showing your previous score(s) just surround each score with <s> and </s>) – ASCII-only – 2018-12-28T00:22:44.637

69 – ASCII-only – 2018-12-28T00:27:15.107

66 – ASCII-only – 2018-12-28T00:29:01.570

2

C (gcc), 157 bytes

I thought that I would be able to avoid including time.h but that just gave segment faults.

#include <time.h>
*t,u;f(){time(&u);t=localtime(&u);t[5]+=t[4]>10&t[3]>25;t[4]=11;t[3]=25;u-=mktime(t);printf("Christmas");for(u/=86400;u++;printf(" Eve"));}

Try it online!

ErikF

Posted 2018-12-24T23:10:06.843

Reputation: 2 149

IMO you should leave out the #include <stdlib.h>, not like it does anything at all here – ASCII-only – 2018-12-26T09:02:00.493

Suggest *t;f(u) instead of *t,u;f() and #import<time.h> instead of #include <time.h> and 5[t=localtime(&u)] instead of t=localtime(&u);t[5] – ceilingcat – 2018-12-28T20:40:45.810

2

Scala, 116 113 bytes

var d=new java.util.Date
print("Christmas")
while(!(""+d).contains("c 25")){print(" Eve");d.setDate(d.getDate+1)}

Try it online!

Where c 25 is short for Dec 25.

Kjetil S.

Posted 2018-12-24T23:10:06.843

Reputation: 1 049

1I think you can use contains("c 25") instead of matches(".*c 25.*") – 12Me21 – 2018-12-29T15:49:17.507

Thanks, three bytes less! – Kjetil S. – 2018-12-29T15:55:30.227

wow, nicely done, toString of date was nice – V. Courtois – 2019-01-02T08:09:39.403

2

Python 3, 106 Bytes

from datetime import*
d=date.today()
print("Christmas"+" Eve"*(date((d+timedelta(6)).year,12,25)-d).days)

Albert Capp

Posted 2018-12-24T23:10:06.843

Reputation: 29

2

JavaScript, 86 77 bytes

Using REPL it would be

for(c='Christmas',d=new Date;!/c 25/.test(d);d=new Date(+d+864e5))c+=' Eve';c

Kudos to ASCII-only for -9 bytes

Vadim

Posted 2018-12-24T23:10:06.843

Reputation: 121

77 – ASCII-only – 2018-12-30T08:33:45.357

Bravo! You did much better than me. May I offer to shave an extra byte?

for(c='Christmas',d=new Date;!/c 25/.test(d=new Date(+d+864e5));)c+=' Eve';c

or this variant:

for(s='Christmas',t=Date.now();!/c 25/.test(new Date(t+=864e5));)s+=' Eve';s

both are 76 bytes. – targumon – 2018-12-31T23:42:53.000

2

Lua, 137 118 bytes.

118 bytes

t,d,month,day=os.time,os.date,1,-6year=d"%Y"+(d"%D">"12/25"and 2or 1)print("Christmas",d" Eve":rep(d("%j",t(_G)-t())))

137 bytes (previous)

t,d=os.time,os.date a=d"*t"a.year,a.month,a.day=a.year+(d"%m%d">"1225"and 1 or 0),12,25 print("Christmas",("Eve "):rep((t(a)-t())/86400))

It's worth noting that it doesn't work in LuaJIT (syntax error)

Tae Hanazono

Posted 2018-12-24T23:10:06.843

Reputation: 19

Welcome to PPCG! Nice first post! – Rɪᴋᴇʀ – 2018-12-31T04:14:01.507

1

MySQL, 102 bytes

pretty much the same as Neil´s T-SQL answer. There seems to be no shorter way in SQL.

select concat("Christmas",repeat(" Eve",datediff(concat(year(now()+interval 6 day),"-12-25"),now())));

Try it online.

Titus

Posted 2018-12-24T23:10:06.843

Reputation: 13 814

1

Scala, 123 bytes

Thanks to ASCII-only's work.

print("Christmas")
var d=new java.util.Date
while(d.getMonth()<11||d.getDate()!=25){print(" Eve");d.setDate(d.getDate()+1)}

Try it online!

Scala + Joda-Time, 140 bytes

import org.joda.time._
var s="Christmas"
var d=DateTime.now
while(d!=d.withDate(d.year().get(),12,25)){d=d.plusDays(1);s+=" Eve"};println(s)

Does not run in TIO since it requires Joda-Time library.

V. Courtois

Posted 2018-12-24T23:10:06.843

Reputation: 868

no joda, 154. sadly can't get java.util.Date to work here :/ – ASCII-only – 2018-12-28T00:12:02.463

148 – ASCII-only – 2018-12-28T00:19:59.197

Ah @ASCII-only I did not count object Main extends App{} chars in my counting (cause I didn't in my other Scala answers either). If we take that out you beat me ^^ – V. Courtois – 2018-12-28T06:40:06.883

The withDate() call is so expensive... – V. Courtois – 2018-12-28T06:41:07.397

>

  • remember you need to specify language as "Scala + Joda-Time" since you use an external library and 2. not going to use my changes? it's shorter plus doesn't need a library :P
  • < – ASCII-only – 2018-12-31T06:17:26.737

    Ah yeah thanks, but I thought you post it in a separate answer..? maybe I dreamt – V. Courtois – 2018-12-31T06:20:17.643

    Nah, I haven't posted it yet. I don't really know Scala anyway so I basically just combined your answer and the Groovy answer >_> – ASCII-only – 2018-12-31T06:25:57.300

    I see :) well I'll add your work today. Thanks! – V. Courtois – 2018-12-31T10:38:08.720

    you don't have to do this, but i'd put the shorter answer first so those that have the PPCG-Design userscript see it in the leaderboard – ASCII-only – 2018-12-31T11:06:11.830

    I'll do it nonetheless. – V. Courtois – 2018-12-31T12:25:21.007

    damn, we were beaten :P – ASCII-only – 2019-01-02T01:08:42.947

    yeah, they used date as a string... :D – V. Courtois – 2019-01-02T08:10:07.973

    1

    MATLAB, 91 bytes

    n=datetime
    x=datetime(year(n+6),12,25)
    s='Christmas'
    while days(x-n)>=1 n=n+1 s=[s,' Eve'] end
    

    MATLAB Non-looper, 100 bytes

    x=datenum(datetime(floor((now+5)/365.2425),12,25))
    d=x-now
    ['Christmas' repmat(' Eve',1,min(d(d>=0)))]
    

    Anthony

    Posted 2018-12-24T23:10:06.843

    Reputation: 111

    1

    05AB1E, 93 89 bytes

    žežfžg)V'ŒÎ[Y¨JŽ9ÚQ#Y`2ô0Kθ4ÖUD2Qi\28X+ë31s<7%É-}‹iY¬>0ëYT`ǝDÅsD12‹i>1ë\1Dǝ¤>2}}ǝVð'»ˆ}J™
    

    Try it online or Try it online with an emulated self-specified date of 'today'.

    Explanation:

    05AB1E doesn't have any builtins for dates, except for receiving the current year/month/day/hours/minutes/seconds/microseconds, so most bytes are used for manual calculations.

    žežfžg)V   # Get the current date and save it in variable `Y`
    'ŒÎ       '# Push compressed string "christmas"
    [          # Start an infinite loop
     Y¨JŽ9ÚQ   #  If the current date is December 25th:
            #  #   Stop the infinite loop
     Y`2ô0Kθ4ÖUD2Qi\28X+ë31s<7%É-}‹iY¬>0ëYT`ǝDÅsD12‹i>1ë\1Dǝ¤>2}}ǝV
               #  Go to the next day, and set `Y` to it
     ð         #  Push a space " "
     '»ˆ      '#  Push compressed string "eve"
    }          # After the infinite loop:
     J         # Join everything on the stack together
      ™        # And make every word title-case (and output the result implicitly)
    

    See this answer of mine to understand how we go to the next day. (PS: 1¾ǝ has been replaced with T`ǝ, since we use the counter_variable somewhere else as well.)

    See this 05AB1E tip of mine (sections How to use the dictionary? and How to compress large integers?) to understand why '»ˆ is "eve"; 'ŒÎ is "christmas"; and Ž9Ú is 1225.

    Kevin Cruijssen

    Posted 2018-12-24T23:10:06.843

    Reputation: 67 575

    Clever golfing! – MilkyWay90 – 2019-01-05T18:35:30.577

    0

    C# (Visual C# Interactive Compiler), 141 bytes

    var g=DateTime.Now;Write("Christmas"+string.Concat(Enumerable.Repeat(" Eve",(new DateTime(g.Year+(g.Day>25&g.Month>11?1:0),12,25)-g).Days)));
    

    Try it online!

    Embodiment of Ignorance

    Posted 2018-12-24T23:10:06.843

    Reputation: 7 014

    1I don't think this works for the 30th of November... – Neil – 2018-12-25T09:56:52.090

    Fixed now, I forgot to add a check to if it was December or not – Embodiment of Ignorance – 2018-12-25T17:58:26.723

    Are you sure about Month > 25? – Neil – 2018-12-25T19:12:55.323

    Fixed it now... – Embodiment of Ignorance – 2018-12-25T20:20:24.447

    Is the ?1:0 nessesary? doesn't & return an integer? – 12Me21 – 2018-12-25T23:33:49.727

    0

    Red, 89 86 84 78 76 bytes

    -10 bytes thanks to ASCII-only!

    does[a: now prin"Christmas"while[a/3 * 31 + a/4 <> 397][prin" Eve"a: a + 1]]
    

    Try it online!

    Galen Ivanov

    Posted 2018-12-24T23:10:06.843

    Reputation: 13 815

    84 – ASCII-only – 2018-12-26T09:04:38.783

    @ASCII-only Hmm, of course! Thank you! – Galen Ivanov – 2018-12-26T10:01:43.217

    78 – ASCII-only – 2018-12-26T23:45:43.630

    76 – ASCII-only – 2018-12-27T00:12:41.820

    @ASCII-only Your 76-byte version does not give correct result when run on Christmas: Date as an argument I feel stupid for not using only now and not now/date. Thank you for your improvements!

    – Galen Ivanov – 2018-12-27T07:20:05.273

    Oh yeah, not that it matters at all, but normally to cross out scores people do <s>score1</s> <s>score2</s> score3 (no commas, strikethrough doesn't reach across scores). Also, yeah that until loop is just a do...while loop in disguise, huh – ASCII-only – 2018-12-27T22:24:47.727

    76? – ASCII-only – 2018-12-27T23:52:51.247

    @ASCII-only Thanks, nice way to get rid of or. – Galen Ivanov – 2018-12-28T07:19:22.873

    0

    Perl 5, 68 bytes

    print"Christmas";print" Eve"while localtime($i++*86400+time)!~/c 25/
    

    Try it online!

    Where c 25 is short for Dec 25.

    Kjetil S.

    Posted 2018-12-24T23:10:06.843

    Reputation: 1 049