Encode the date in Christmas Eve format
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, wheren
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 code-golf, 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.
code-golf string date
|
show 9 more comments
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, wheren
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 code-golf, 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.
code-golf string date
1
Somehow I knew that this was going to be a PPCG challenge the moment I saw the cartoon - +1 from me
– Black Owl Kai
yesterday
@BlackOwlKai what cartoon?
– PyRulez
yesterday
6
A xkcd cartoon that was published today. imgs.xkcd.com/comics/christmas_eve_eve.png
– Black Owl Kai
yesterday
3
@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
yesterday
You should specify that you mean Dec 25 for "Christmas", unless you want submissions that use a local date or calendar.
– Sparr
yesterday
|
show 9 more comments
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, wheren
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 code-golf, 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.
code-golf string date
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, wheren
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 code-golf, 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.
code-golf string date
code-golf string date
edited yesterday
asked yesterday
PyRulez
3,42242056
3,42242056
1
Somehow I knew that this was going to be a PPCG challenge the moment I saw the cartoon - +1 from me
– Black Owl Kai
yesterday
@BlackOwlKai what cartoon?
– PyRulez
yesterday
6
A xkcd cartoon that was published today. imgs.xkcd.com/comics/christmas_eve_eve.png
– Black Owl Kai
yesterday
3
@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
yesterday
You should specify that you mean Dec 25 for "Christmas", unless you want submissions that use a local date or calendar.
– Sparr
yesterday
|
show 9 more comments
1
Somehow I knew that this was going to be a PPCG challenge the moment I saw the cartoon - +1 from me
– Black Owl Kai
yesterday
@BlackOwlKai what cartoon?
– PyRulez
yesterday
6
A xkcd cartoon that was published today. imgs.xkcd.com/comics/christmas_eve_eve.png
– Black Owl Kai
yesterday
3
@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
yesterday
You should specify that you mean Dec 25 for "Christmas", unless you want submissions that use a local date or calendar.
– Sparr
yesterday
1
1
Somehow I knew that this was going to be a PPCG challenge the moment I saw the cartoon - +1 from me
– Black Owl Kai
yesterday
Somehow I knew that this was going to be a PPCG challenge the moment I saw the cartoon - +1 from me
– Black Owl Kai
yesterday
@BlackOwlKai what cartoon?
– PyRulez
yesterday
@BlackOwlKai what cartoon?
– PyRulez
yesterday
6
6
A xkcd cartoon that was published today. imgs.xkcd.com/comics/christmas_eve_eve.png
– Black Owl Kai
yesterday
A xkcd cartoon that was published today. imgs.xkcd.com/comics/christmas_eve_eve.png
– Black Owl Kai
yesterday
3
3
@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
yesterday
@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
yesterday
You should specify that you mean Dec 25 for "Christmas", unless you want submissions that use a local date or calendar.
– Sparr
yesterday
You should specify that you mean Dec 25 for "Christmas", unless you want submissions that use a local date or calendar.
– Sparr
yesterday
|
show 9 more comments
18 Answers
18
active
oldest
votes
SmileBASIC, 73 71 67 bytes
?"Christmas";
@L?" Eve"*(D!=O);
O=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.
3
pure genius ...
– FlipTack
yesterday
3
This made me Smile...
– Neil
22 hours ago
2
Nice! 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
12 hours ago
1
The 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
12 hours ago
add a comment |
R, 112 106 bytes
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".
You only usey
once so you can just use it directly for 108 bytes.
– Giuseppe
yesterday
Also wouldz[z>=0][1]
work instead ofmin
?
– Giuseppe
yesterday
73 bytes. According to the last comment, the program must output the text based on the day it runs. Merry christmas BTW ! :D
– digEmAll
yesterday
1
Tweaked yours for 72 bytes, @digEmAll. Merry Christmas!
– J.Doe
yesterday
add a comment |
Excel formula, 62 bytes
="Christmas"&REPT(" Eve",DATE(YEAR(TODAY()+6),12,25)-TODAY())
New contributor
1
I thinkYEAR(TODAY()+6)
always returns the correct year, thus avoiding the condition.
– Neil
17 hours ago
Shouldn't it be > (instead of >=) ?
– targumon
16 hours ago
targumon, Yes, that outputs "Christmas" on it's own
– Richard Crossley
12 hours ago
Neil, that works nicely: ="Christmas"&REPT(" Eve",DATE(YEAR(TODAY()+6),12,25)-TODAY())
– Richard Crossley
12 hours ago
add a comment |
Perl 6, 61 bytes
say 'Christmas'~' Eve'x(Date.today...^{.month==12&&.day==25})
Try it online!
Date.today ...^ { .month == 12 && .day == 25 }
is the sequence of dates starting at today and ending the day before Christmas. The string " Eve"
is replicated a number of times equal to the length of that sequence, and is output after the string "Christmas"
.
I think you can replace the end condition with/12-25/
– Jo King
3 hours ago
add a comment |
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 thatdate
[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 Christmas4×
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
add a comment |
C# (Visual C# Interactive Compiler), 92 bytes
Write("Christmas");for(var t=DateTime.Now;t.Month<12|t.Day!=25;t=t.AddDays(1))Write(" Eve");
Try it online!
My strategy is pretty straightforward:
- Initialize a loop variable
t
to the current date - Print
Eve
ift
is not Christmas - Add a day to
t
and repeat
I tried some fancier things, but this way required the fewest bytes.
add a comment |
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
add a comment |
T-SQL, 92 bytes
SELECT 'Christmas'+REPLICATE(' Eve',DATEDIFF(DAY,GETDATE(),STR(YEAR(GETDATE()+6))+'-12-25'))
add a comment |
PHP, 61 bytes
Christmas<?for($t=time();date(md,$t+=86400)-1226;)echo" Eve";
Run with -n
or try it online.
add a comment |
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.
add a comment |
Python 2, 129 bytes / Python 3, 130 bytes
of course, one less byte 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])
105 bytes
– tsh
yesterday
@tsh That's an amazing approach!
– iBug
23 hours ago
add a comment |
PHP, 84 bytes
Probably doesn't work that well.
$d=intval(date("z"));echo("Christmas ".str_repeat("Eve ",(358-$d)<0?724-$d:358-$d));
2
Will this work in leap year?
– tsh
yesterday
No sir it will NOT. I have no idea how to implement that.
– Adrian Zhang
19 hours ago
a little long, but a nice approach. Take a look atdate("L")
:1
for leap year,0
otherwise. Don´t forget to use it for the next year too. Try($d=date(z))>359
; you can useChristmas<?=
that way.
– Titus
16 hours ago
add a comment |
Groovy, 156 bytes
import java.time.LocalDate as D
d=D.now()
c=D.of(d.year,12,25)
'Chistmas'+' Eve'*java.time.temporal.ChronoUnit.DAYS.between(d,d>c?c.withYear(d.year+1):c)
New contributor
add a comment |
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!
1
I don't think this works for the 30th of November...
– Neil
yesterday
Fixed now, I forgot to add a check to if it was December or not
– Embodiment of Ignorance
19 hours ago
Are you sure about Month > 25?
– Neil
17 hours ago
Fixed it now...
– Embodiment of Ignorance
16 hours ago
Is the ?1:0 nessesary? doesn't & return an integer?
– 12Me21
13 hours ago
add a comment |
JavaScript, 135 131 121 92 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
New contributor
1
I think you can uset.getMonth()/t.getDate-.48
to check if date is not december 25th
– 12Me21
12 hours ago
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
11 hours ago
1
Welcome to the site! You can use a 4 space indent to make your code blocks look better.
– Wît Wisarhd
9 hours ago
1
Welcome to PPCG!
– Shaggy
1 hour ago
add a comment |
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!
IMO you should leave out the#include <stdlib.h>
, not like it does anything at all here
– ASCII-only
4 hours ago
add a comment |
Red, 89, 86 84 bytes
-2 bytes thanks to ASCII-only!
does[a: now/date prin"Christmas"while[(a/3 <> 12)or(a/4 <> 25)][prin" Eve"a: a + 1]]
Try it online!
84
– ASCII-only
3 hours ago
@ASCII-only Hmm, of course! Thank you!
– Galen Ivanov
3 hours ago
add a comment |
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 eve
s).
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "200"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178003%2fencode-the-date-in-christmas-eve-format%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
18 Answers
18
active
oldest
votes
18 Answers
18
active
oldest
votes
active
oldest
votes
active
oldest
votes
SmileBASIC, 73 71 67 bytes
?"Christmas";
@L?" Eve"*(D!=O);
O=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.
3
pure genius ...
– FlipTack
yesterday
3
This made me Smile...
– Neil
22 hours ago
2
Nice! 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
12 hours ago
1
The 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
12 hours ago
add a comment |
SmileBASIC, 73 71 67 bytes
?"Christmas";
@L?" Eve"*(D!=O);
O=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.
3
pure genius ...
– FlipTack
yesterday
3
This made me Smile...
– Neil
22 hours ago
2
Nice! 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
12 hours ago
1
The 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
12 hours ago
add a comment |
SmileBASIC, 73 71 67 bytes
?"Christmas";
@L?" Eve"*(D!=O);
O=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.
SmileBASIC, 73 71 67 bytes
?"Christmas";
@L?" Eve"*(D!=O);
O=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.
edited 19 hours ago
answered yesterday
12Me21
5,05711136
5,05711136
3
pure genius ...
– FlipTack
yesterday
3
This made me Smile...
– Neil
22 hours ago
2
Nice! 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
12 hours ago
1
The 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
12 hours ago
add a comment |
3
pure genius ...
– FlipTack
yesterday
3
This made me Smile...
– Neil
22 hours ago
2
Nice! 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
12 hours ago
1
The 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
12 hours ago
3
3
pure genius ...
– FlipTack
yesterday
pure genius ...
– FlipTack
yesterday
3
3
This made me Smile...
– Neil
22 hours ago
This made me Smile...
– Neil
22 hours ago
2
2
Nice! 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
12 hours ago
Nice! 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
12 hours ago
1
1
The 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
12 hours ago
The 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
12 hours ago
add a comment |
R, 112 106 bytes
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".
You only usey
once so you can just use it directly for 108 bytes.
– Giuseppe
yesterday
Also wouldz[z>=0][1]
work instead ofmin
?
– Giuseppe
yesterday
73 bytes. According to the last comment, the program must output the text based on the day it runs. Merry christmas BTW ! :D
– digEmAll
yesterday
1
Tweaked yours for 72 bytes, @digEmAll. Merry Christmas!
– J.Doe
yesterday
add a comment |
R, 112 106 bytes
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".
You only usey
once so you can just use it directly for 108 bytes.
– Giuseppe
yesterday
Also wouldz[z>=0][1]
work instead ofmin
?
– Giuseppe
yesterday
73 bytes. According to the last comment, the program must output the text based on the day it runs. Merry christmas BTW ! :D
– digEmAll
yesterday
1
Tweaked yours for 72 bytes, @digEmAll. Merry Christmas!
– J.Doe
yesterday
add a comment |
R, 112 106 bytes
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".
R, 112 106 bytes
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".
edited yesterday
answered yesterday
ngm
3,26924
3,26924
You only usey
once so you can just use it directly for 108 bytes.
– Giuseppe
yesterday
Also wouldz[z>=0][1]
work instead ofmin
?
– Giuseppe
yesterday
73 bytes. According to the last comment, the program must output the text based on the day it runs. Merry christmas BTW ! :D
– digEmAll
yesterday
1
Tweaked yours for 72 bytes, @digEmAll. Merry Christmas!
– J.Doe
yesterday
add a comment |
You only usey
once so you can just use it directly for 108 bytes.
– Giuseppe
yesterday
Also wouldz[z>=0][1]
work instead ofmin
?
– Giuseppe
yesterday
73 bytes. According to the last comment, the program must output the text based on the day it runs. Merry christmas BTW ! :D
– digEmAll
yesterday
1
Tweaked yours for 72 bytes, @digEmAll. Merry Christmas!
– J.Doe
yesterday
You only use
y
once so you can just use it directly for 108 bytes.– Giuseppe
yesterday
You only use
y
once so you can just use it directly for 108 bytes.– Giuseppe
yesterday
Also would
z[z>=0][1]
work instead of min
?– Giuseppe
yesterday
Also would
z[z>=0][1]
work instead of min
?– Giuseppe
yesterday
73 bytes. According to the last comment, the program must output the text based on the day it runs. Merry christmas BTW ! :D
– digEmAll
yesterday
73 bytes. According to the last comment, the program must output the text based on the day it runs. Merry christmas BTW ! :D
– digEmAll
yesterday
1
1
Tweaked yours for 72 bytes, @digEmAll. Merry Christmas!
– J.Doe
yesterday
Tweaked yours for 72 bytes, @digEmAll. Merry Christmas!
– J.Doe
yesterday
add a comment |
Excel formula, 62 bytes
="Christmas"&REPT(" Eve",DATE(YEAR(TODAY()+6),12,25)-TODAY())
New contributor
1
I thinkYEAR(TODAY()+6)
always returns the correct year, thus avoiding the condition.
– Neil
17 hours ago
Shouldn't it be > (instead of >=) ?
– targumon
16 hours ago
targumon, Yes, that outputs "Christmas" on it's own
– Richard Crossley
12 hours ago
Neil, that works nicely: ="Christmas"&REPT(" Eve",DATE(YEAR(TODAY()+6),12,25)-TODAY())
– Richard Crossley
12 hours ago
add a comment |
Excel formula, 62 bytes
="Christmas"&REPT(" Eve",DATE(YEAR(TODAY()+6),12,25)-TODAY())
New contributor
1
I thinkYEAR(TODAY()+6)
always returns the correct year, thus avoiding the condition.
– Neil
17 hours ago
Shouldn't it be > (instead of >=) ?
– targumon
16 hours ago
targumon, Yes, that outputs "Christmas" on it's own
– Richard Crossley
12 hours ago
Neil, that works nicely: ="Christmas"&REPT(" Eve",DATE(YEAR(TODAY()+6),12,25)-TODAY())
– Richard Crossley
12 hours ago
add a comment |
Excel formula, 62 bytes
="Christmas"&REPT(" Eve",DATE(YEAR(TODAY()+6),12,25)-TODAY())
New contributor
Excel formula, 62 bytes
="Christmas"&REPT(" Eve",DATE(YEAR(TODAY()+6),12,25)-TODAY())
New contributor
edited 12 hours ago
New contributor
answered 23 hours ago
Richard Crossley
614
614
New contributor
New contributor
1
I thinkYEAR(TODAY()+6)
always returns the correct year, thus avoiding the condition.
– Neil
17 hours ago
Shouldn't it be > (instead of >=) ?
– targumon
16 hours ago
targumon, Yes, that outputs "Christmas" on it's own
– Richard Crossley
12 hours ago
Neil, that works nicely: ="Christmas"&REPT(" Eve",DATE(YEAR(TODAY()+6),12,25)-TODAY())
– Richard Crossley
12 hours ago
add a comment |
1
I thinkYEAR(TODAY()+6)
always returns the correct year, thus avoiding the condition.
– Neil
17 hours ago
Shouldn't it be > (instead of >=) ?
– targumon
16 hours ago
targumon, Yes, that outputs "Christmas" on it's own
– Richard Crossley
12 hours ago
Neil, that works nicely: ="Christmas"&REPT(" Eve",DATE(YEAR(TODAY()+6),12,25)-TODAY())
– Richard Crossley
12 hours ago
1
1
I think
YEAR(TODAY()+6)
always returns the correct year, thus avoiding the condition.– Neil
17 hours ago
I think
YEAR(TODAY()+6)
always returns the correct year, thus avoiding the condition.– Neil
17 hours ago
Shouldn't it be > (instead of >=) ?
– targumon
16 hours ago
Shouldn't it be > (instead of >=) ?
– targumon
16 hours ago
targumon, Yes, that outputs "Christmas" on it's own
– Richard Crossley
12 hours ago
targumon, Yes, that outputs "Christmas" on it's own
– Richard Crossley
12 hours ago
Neil, that works nicely: ="Christmas"&REPT(" Eve",DATE(YEAR(TODAY()+6),12,25)-TODAY())
– Richard Crossley
12 hours ago
Neil, that works nicely: ="Christmas"&REPT(" Eve",DATE(YEAR(TODAY()+6),12,25)-TODAY())
– Richard Crossley
12 hours ago
add a comment |
Perl 6, 61 bytes
say 'Christmas'~' Eve'x(Date.today...^{.month==12&&.day==25})
Try it online!
Date.today ...^ { .month == 12 && .day == 25 }
is the sequence of dates starting at today and ending the day before Christmas. The string " Eve"
is replicated a number of times equal to the length of that sequence, and is output after the string "Christmas"
.
I think you can replace the end condition with/12-25/
– Jo King
3 hours ago
add a comment |
Perl 6, 61 bytes
say 'Christmas'~' Eve'x(Date.today...^{.month==12&&.day==25})
Try it online!
Date.today ...^ { .month == 12 && .day == 25 }
is the sequence of dates starting at today and ending the day before Christmas. The string " Eve"
is replicated a number of times equal to the length of that sequence, and is output after the string "Christmas"
.
I think you can replace the end condition with/12-25/
– Jo King
3 hours ago
add a comment |
Perl 6, 61 bytes
say 'Christmas'~' Eve'x(Date.today...^{.month==12&&.day==25})
Try it online!
Date.today ...^ { .month == 12 && .day == 25 }
is the sequence of dates starting at today and ending the day before Christmas. The string " Eve"
is replicated a number of times equal to the length of that sequence, and is output after the string "Christmas"
.
Perl 6, 61 bytes
say 'Christmas'~' Eve'x(Date.today...^{.month==12&&.day==25})
Try it online!
Date.today ...^ { .month == 12 && .day == 25 }
is the sequence of dates starting at today and ending the day before Christmas. The string " Eve"
is replicated a number of times equal to the length of that sequence, and is output after the string "Christmas"
.
answered yesterday
Sean
3,32636
3,32636
I think you can replace the end condition with/12-25/
– Jo King
3 hours ago
add a comment |
I think you can replace the end condition with/12-25/
– Jo King
3 hours ago
I think you can replace the end condition with
/12-25/
– Jo King
3 hours ago
I think you can replace the end condition with
/12-25/
– Jo King
3 hours ago
add a comment |
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 thatdate
[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 Christmas4×
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
add a comment |
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 thatdate
[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 Christmas4×
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
add a comment |
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 thatdate
[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 Christmas4×
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
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 thatdate
[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 Christmas4×
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
edited yesterday
answered yesterday
Adám
28.6k269188
28.6k269188
add a comment |
add a comment |
C# (Visual C# Interactive Compiler), 92 bytes
Write("Christmas");for(var t=DateTime.Now;t.Month<12|t.Day!=25;t=t.AddDays(1))Write(" Eve");
Try it online!
My strategy is pretty straightforward:
- Initialize a loop variable
t
to the current date - Print
Eve
ift
is not Christmas - Add a day to
t
and repeat
I tried some fancier things, but this way required the fewest bytes.
add a comment |
C# (Visual C# Interactive Compiler), 92 bytes
Write("Christmas");for(var t=DateTime.Now;t.Month<12|t.Day!=25;t=t.AddDays(1))Write(" Eve");
Try it online!
My strategy is pretty straightforward:
- Initialize a loop variable
t
to the current date - Print
Eve
ift
is not Christmas - Add a day to
t
and repeat
I tried some fancier things, but this way required the fewest bytes.
add a comment |
C# (Visual C# Interactive Compiler), 92 bytes
Write("Christmas");for(var t=DateTime.Now;t.Month<12|t.Day!=25;t=t.AddDays(1))Write(" Eve");
Try it online!
My strategy is pretty straightforward:
- Initialize a loop variable
t
to the current date - Print
Eve
ift
is not Christmas - Add a day to
t
and repeat
I tried some fancier things, but this way required the fewest bytes.
C# (Visual C# Interactive Compiler), 92 bytes
Write("Christmas");for(var t=DateTime.Now;t.Month<12|t.Day!=25;t=t.AddDays(1))Write(" Eve");
Try it online!
My strategy is pretty straightforward:
- Initialize a loop variable
t
to the current date - Print
Eve
ift
is not Christmas - Add a day to
t
and repeat
I tried some fancier things, but this way required the fewest bytes.
edited 16 hours ago
answered yesterday
dana
38125
38125
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered 23 hours ago
iBug
1,247730
1,247730
add a comment |
add a comment |
T-SQL, 92 bytes
SELECT 'Christmas'+REPLICATE(' Eve',DATEDIFF(DAY,GETDATE(),STR(YEAR(GETDATE()+6))+'-12-25'))
add a comment |
T-SQL, 92 bytes
SELECT 'Christmas'+REPLICATE(' Eve',DATEDIFF(DAY,GETDATE(),STR(YEAR(GETDATE()+6))+'-12-25'))
add a comment |
T-SQL, 92 bytes
SELECT 'Christmas'+REPLICATE(' Eve',DATEDIFF(DAY,GETDATE(),STR(YEAR(GETDATE()+6))+'-12-25'))
T-SQL, 92 bytes
SELECT 'Christmas'+REPLICATE(' Eve',DATEDIFF(DAY,GETDATE(),STR(YEAR(GETDATE()+6))+'-12-25'))
answered 17 hours ago
Neil
79.3k744177
79.3k744177
add a comment |
add a comment |
PHP, 61 bytes
Christmas<?for($t=time();date(md,$t+=86400)-1226;)echo" Eve";
Run with -n
or try it online.
add a comment |
PHP, 61 bytes
Christmas<?for($t=time();date(md,$t+=86400)-1226;)echo" Eve";
Run with -n
or try it online.
add a comment |
PHP, 61 bytes
Christmas<?for($t=time();date(md,$t+=86400)-1226;)echo" Eve";
Run with -n
or try it online.
PHP, 61 bytes
Christmas<?for($t=time();date(md,$t+=86400)-1226;)echo" Eve";
Run with -n
or try it online.
answered 17 hours ago
Titus
13k11237
13k11237
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered 16 hours ago
Titus
13k11237
13k11237
add a comment |
add a comment |
Python 2, 129 bytes / Python 3, 130 bytes
of course, one less byte 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])
105 bytes
– tsh
yesterday
@tsh That's an amazing approach!
– iBug
23 hours ago
add a comment |
Python 2, 129 bytes / Python 3, 130 bytes
of course, one less byte 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])
105 bytes
– tsh
yesterday
@tsh That's an amazing approach!
– iBug
23 hours ago
add a comment |
Python 2, 129 bytes / Python 3, 130 bytes
of course, one less byte 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])
Python 2, 129 bytes / Python 3, 130 bytes
of course, one less byte 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])
edited yesterday
answered yesterday
iBug
1,247730
1,247730
105 bytes
– tsh
yesterday
@tsh That's an amazing approach!
– iBug
23 hours ago
add a comment |
105 bytes
– tsh
yesterday
@tsh That's an amazing approach!
– iBug
23 hours ago
105 bytes
– tsh
yesterday
105 bytes
– tsh
yesterday
@tsh That's an amazing approach!
– iBug
23 hours ago
@tsh That's an amazing approach!
– iBug
23 hours ago
add a comment |
PHP, 84 bytes
Probably doesn't work that well.
$d=intval(date("z"));echo("Christmas ".str_repeat("Eve ",(358-$d)<0?724-$d:358-$d));
2
Will this work in leap year?
– tsh
yesterday
No sir it will NOT. I have no idea how to implement that.
– Adrian Zhang
19 hours ago
a little long, but a nice approach. Take a look atdate("L")
:1
for leap year,0
otherwise. Don´t forget to use it for the next year too. Try($d=date(z))>359
; you can useChristmas<?=
that way.
– Titus
16 hours ago
add a comment |
PHP, 84 bytes
Probably doesn't work that well.
$d=intval(date("z"));echo("Christmas ".str_repeat("Eve ",(358-$d)<0?724-$d:358-$d));
2
Will this work in leap year?
– tsh
yesterday
No sir it will NOT. I have no idea how to implement that.
– Adrian Zhang
19 hours ago
a little long, but a nice approach. Take a look atdate("L")
:1
for leap year,0
otherwise. Don´t forget to use it for the next year too. Try($d=date(z))>359
; you can useChristmas<?=
that way.
– Titus
16 hours ago
add a comment |
PHP, 84 bytes
Probably doesn't work that well.
$d=intval(date("z"));echo("Christmas ".str_repeat("Eve ",(358-$d)<0?724-$d:358-$d));
PHP, 84 bytes
Probably doesn't work that well.
$d=intval(date("z"));echo("Christmas ".str_repeat("Eve ",(358-$d)<0?724-$d:358-$d));
answered yesterday
Adrian Zhang
20715
20715
2
Will this work in leap year?
– tsh
yesterday
No sir it will NOT. I have no idea how to implement that.
– Adrian Zhang
19 hours ago
a little long, but a nice approach. Take a look atdate("L")
:1
for leap year,0
otherwise. Don´t forget to use it for the next year too. Try($d=date(z))>359
; you can useChristmas<?=
that way.
– Titus
16 hours ago
add a comment |
2
Will this work in leap year?
– tsh
yesterday
No sir it will NOT. I have no idea how to implement that.
– Adrian Zhang
19 hours ago
a little long, but a nice approach. Take a look atdate("L")
:1
for leap year,0
otherwise. Don´t forget to use it for the next year too. Try($d=date(z))>359
; you can useChristmas<?=
that way.
– Titus
16 hours ago
2
2
Will this work in leap year?
– tsh
yesterday
Will this work in leap year?
– tsh
yesterday
No sir it will NOT. I have no idea how to implement that.
– Adrian Zhang
19 hours ago
No sir it will NOT. I have no idea how to implement that.
– Adrian Zhang
19 hours ago
a little long, but a nice approach. Take a look at
date("L")
: 1
for leap year, 0
otherwise. Don´t forget to use it for the next year too. Try ($d=date(z))>359
; you can use Christmas<?=
that way.– Titus
16 hours ago
a little long, but a nice approach. Take a look at
date("L")
: 1
for leap year, 0
otherwise. Don´t forget to use it for the next year too. Try ($d=date(z))>359
; you can use Christmas<?=
that way.– Titus
16 hours ago
add a comment |
Groovy, 156 bytes
import java.time.LocalDate as D
d=D.now()
c=D.of(d.year,12,25)
'Chistmas'+' Eve'*java.time.temporal.ChronoUnit.DAYS.between(d,d>c?c.withYear(d.year+1):c)
New contributor
add a comment |
Groovy, 156 bytes
import java.time.LocalDate as D
d=D.now()
c=D.of(d.year,12,25)
'Chistmas'+' Eve'*java.time.temporal.ChronoUnit.DAYS.between(d,d>c?c.withYear(d.year+1):c)
New contributor
add a comment |
Groovy, 156 bytes
import java.time.LocalDate as D
d=D.now()
c=D.of(d.year,12,25)
'Chistmas'+' Eve'*java.time.temporal.ChronoUnit.DAYS.between(d,d>c?c.withYear(d.year+1):c)
New contributor
Groovy, 156 bytes
import java.time.LocalDate as D
d=D.now()
c=D.of(d.year,12,25)
'Chistmas'+' Eve'*java.time.temporal.ChronoUnit.DAYS.between(d,d>c?c.withYear(d.year+1):c)
New contributor
New contributor
answered 22 hours ago
bdkosher
1011
1011
New contributor
New contributor
add a comment |
add a comment |
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!
1
I don't think this works for the 30th of November...
– Neil
yesterday
Fixed now, I forgot to add a check to if it was December or not
– Embodiment of Ignorance
19 hours ago
Are you sure about Month > 25?
– Neil
17 hours ago
Fixed it now...
– Embodiment of Ignorance
16 hours ago
Is the ?1:0 nessesary? doesn't & return an integer?
– 12Me21
13 hours ago
add a comment |
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!
1
I don't think this works for the 30th of November...
– Neil
yesterday
Fixed now, I forgot to add a check to if it was December or not
– Embodiment of Ignorance
19 hours ago
Are you sure about Month > 25?
– Neil
17 hours ago
Fixed it now...
– Embodiment of Ignorance
16 hours ago
Is the ?1:0 nessesary? doesn't & return an integer?
– 12Me21
13 hours ago
add a comment |
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!
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!
edited 16 hours ago
answered yesterday
Embodiment of Ignorance
24711
24711
1
I don't think this works for the 30th of November...
– Neil
yesterday
Fixed now, I forgot to add a check to if it was December or not
– Embodiment of Ignorance
19 hours ago
Are you sure about Month > 25?
– Neil
17 hours ago
Fixed it now...
– Embodiment of Ignorance
16 hours ago
Is the ?1:0 nessesary? doesn't & return an integer?
– 12Me21
13 hours ago
add a comment |
1
I don't think this works for the 30th of November...
– Neil
yesterday
Fixed now, I forgot to add a check to if it was December or not
– Embodiment of Ignorance
19 hours ago
Are you sure about Month > 25?
– Neil
17 hours ago
Fixed it now...
– Embodiment of Ignorance
16 hours ago
Is the ?1:0 nessesary? doesn't & return an integer?
– 12Me21
13 hours ago
1
1
I don't think this works for the 30th of November...
– Neil
yesterday
I don't think this works for the 30th of November...
– Neil
yesterday
Fixed now, I forgot to add a check to if it was December or not
– Embodiment of Ignorance
19 hours ago
Fixed now, I forgot to add a check to if it was December or not
– Embodiment of Ignorance
19 hours ago
Are you sure about Month > 25?
– Neil
17 hours ago
Are you sure about Month > 25?
– Neil
17 hours ago
Fixed it now...
– Embodiment of Ignorance
16 hours ago
Fixed it now...
– Embodiment of Ignorance
16 hours ago
Is the ?1:0 nessesary? doesn't & return an integer?
– 12Me21
13 hours ago
Is the ?1:0 nessesary? doesn't & return an integer?
– 12Me21
13 hours ago
add a comment |
JavaScript, 135 131 121 92 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
New contributor
1
I think you can uset.getMonth()/t.getDate-.48
to check if date is not december 25th
– 12Me21
12 hours ago
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
11 hours ago
1
Welcome to the site! You can use a 4 space indent to make your code blocks look better.
– Wît Wisarhd
9 hours ago
1
Welcome to PPCG!
– Shaggy
1 hour ago
add a comment |
JavaScript, 135 131 121 92 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
New contributor
1
I think you can uset.getMonth()/t.getDate-.48
to check if date is not december 25th
– 12Me21
12 hours ago
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
11 hours ago
1
Welcome to the site! You can use a 4 space indent to make your code blocks look better.
– Wît Wisarhd
9 hours ago
1
Welcome to PPCG!
– Shaggy
1 hour ago
add a comment |
JavaScript, 135 131 121 92 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
New contributor
JavaScript, 135 131 121 92 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
New contributor
edited 6 hours ago
New contributor
answered 13 hours ago
targumon
1013
1013
New contributor
New contributor
1
I think you can uset.getMonth()/t.getDate-.48
to check if date is not december 25th
– 12Me21
12 hours ago
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
11 hours ago
1
Welcome to the site! You can use a 4 space indent to make your code blocks look better.
– Wît Wisarhd
9 hours ago
1
Welcome to PPCG!
– Shaggy
1 hour ago
add a comment |
1
I think you can uset.getMonth()/t.getDate-.48
to check if date is not december 25th
– 12Me21
12 hours ago
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
11 hours ago
1
Welcome to the site! You can use a 4 space indent to make your code blocks look better.
– Wît Wisarhd
9 hours ago
1
Welcome to PPCG!
– Shaggy
1 hour ago
1
1
I think you can use
t.getMonth()/t.getDate-.48
to check if date is not december 25th– 12Me21
12 hours ago
I think you can use
t.getMonth()/t.getDate-.48
to check if date is not december 25th– 12Me21
12 hours ago
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
11 hours ago
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
11 hours ago
1
1
Welcome to the site! You can use a 4 space indent to make your code blocks look better.
– Wît Wisarhd
9 hours ago
Welcome to the site! You can use a 4 space indent to make your code blocks look better.
– Wît Wisarhd
9 hours ago
1
1
Welcome to PPCG!
– Shaggy
1 hour ago
Welcome to PPCG!
– Shaggy
1 hour ago
add a comment |
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!
IMO you should leave out the#include <stdlib.h>
, not like it does anything at all here
– ASCII-only
4 hours ago
add a comment |
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!
IMO you should leave out the#include <stdlib.h>
, not like it does anything at all here
– ASCII-only
4 hours ago
add a comment |
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!
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!
edited 5 hours ago
answered 12 hours ago
ErikF
1,25917
1,25917
IMO you should leave out the#include <stdlib.h>
, not like it does anything at all here
– ASCII-only
4 hours ago
add a comment |
IMO you should leave out the#include <stdlib.h>
, not like it does anything at all here
– ASCII-only
4 hours ago
IMO you should leave out the
#include <stdlib.h>
, not like it does anything at all here– ASCII-only
4 hours ago
IMO you should leave out the
#include <stdlib.h>
, not like it does anything at all here– ASCII-only
4 hours ago
add a comment |
Red, 89, 86 84 bytes
-2 bytes thanks to ASCII-only!
does[a: now/date prin"Christmas"while[(a/3 <> 12)or(a/4 <> 25)][prin" Eve"a: a + 1]]
Try it online!
84
– ASCII-only
3 hours ago
@ASCII-only Hmm, of course! Thank you!
– Galen Ivanov
3 hours ago
add a comment |
Red, 89, 86 84 bytes
-2 bytes thanks to ASCII-only!
does[a: now/date prin"Christmas"while[(a/3 <> 12)or(a/4 <> 25)][prin" Eve"a: a + 1]]
Try it online!
84
– ASCII-only
3 hours ago
@ASCII-only Hmm, of course! Thank you!
– Galen Ivanov
3 hours ago
add a comment |
Red, 89, 86 84 bytes
-2 bytes thanks to ASCII-only!
does[a: now/date prin"Christmas"while[(a/3 <> 12)or(a/4 <> 25)][prin" Eve"a: a + 1]]
Try it online!
Red, 89, 86 84 bytes
-2 bytes thanks to ASCII-only!
does[a: now/date prin"Christmas"while[(a/3 <> 12)or(a/4 <> 25)][prin" Eve"a: a + 1]]
Try it online!
edited 3 hours ago
answered yesterday
Galen Ivanov
6,29711032
6,29711032
84
– ASCII-only
3 hours ago
@ASCII-only Hmm, of course! Thank you!
– Galen Ivanov
3 hours ago
add a comment |
84
– ASCII-only
3 hours ago
@ASCII-only Hmm, of course! Thank you!
– Galen Ivanov
3 hours ago
84
– ASCII-only
3 hours ago
84
– ASCII-only
3 hours ago
@ASCII-only Hmm, of course! Thank you!
– Galen Ivanov
3 hours ago
@ASCII-only Hmm, of course! Thank you!
– Galen Ivanov
3 hours ago
add a comment |
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 eve
s).
add a comment |
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 eve
s).
add a comment |
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 eve
s).
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 eve
s).
answered 21 mins ago
briantist
2,910920
2,910920
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178003%2fencode-the-date-in-christmas-eve-format%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Somehow I knew that this was going to be a PPCG challenge the moment I saw the cartoon - +1 from me
– Black Owl Kai
yesterday
@BlackOwlKai what cartoon?
– PyRulez
yesterday
6
A xkcd cartoon that was published today. imgs.xkcd.com/comics/christmas_eve_eve.png
– Black Owl Kai
yesterday
3
@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
yesterday
You should specify that you mean Dec 25 for "Christmas", unless you want submissions that use a local date or calendar.
– Sparr
yesterday