It's a yearly task, alright
$begingroup$
Given a number 1≤n≤365, output the nth day of the year in "Day-numberth Month" format. For example, given 1, you should output "1st January", without "of".
The Gregorian calendar will be used and the program should not account for leap years, so your program should never output "29th February" in any circumstance. Any method can be used, as long as it follows the "Day-numberth Month" format mentioned before. Your program should also output ordinals correctly, meaning it should always output 1st, 2nd, 3rd, should 1, 2 or 3 respectively be the day numbers for any input. Leading spaces or other indentation are allowed.
This is code golf, so the shortest solution by characters wins.
Test cases:
1 gives 1st January
2 gives 2nd January
3 gives 3rd January
365 gives 31st December
60 gives 1st March
11 gives 11th January
code-golf date
$endgroup$
|
show 8 more comments
$begingroup$
Given a number 1≤n≤365, output the nth day of the year in "Day-numberth Month" format. For example, given 1, you should output "1st January", without "of".
The Gregorian calendar will be used and the program should not account for leap years, so your program should never output "29th February" in any circumstance. Any method can be used, as long as it follows the "Day-numberth Month" format mentioned before. Your program should also output ordinals correctly, meaning it should always output 1st, 2nd, 3rd, should 1, 2 or 3 respectively be the day numbers for any input. Leading spaces or other indentation are allowed.
This is code golf, so the shortest solution by characters wins.
Test cases:
1 gives 1st January
2 gives 2nd January
3 gives 3rd January
365 gives 31st December
60 gives 1st March
11 gives 11th January
code-golf date
$endgroup$
$begingroup$
What is "Day-number Month" format? I'm assuming it's "20th March"? Or is it "20 March"? That makes a pretty big difference, if you need ordinals.
$endgroup$
– Riker
7 hours ago
3
$begingroup$
Also, do you need to force an error message on numbers > 365? Can the program just assume that's invalid input and it won't need to handle that?
$endgroup$
– Riker
7 hours ago
4
$begingroup$
As not everyone is a native English speaker, you may want to add that day numbers 11, 12, and 13 get "th", numbers ending in "1" get "st", "2" get "nd", "3" get "rd", and all other get "th".
$endgroup$
– Adám
7 hours ago
4
$begingroup$
Whoa, don't accept answers so quickly. Especially not wrong answers!
$endgroup$
– Adám
6 hours ago
3
$begingroup$
You should add at least11
(11th January) and21
(21st January) to the test cases.
$endgroup$
– Arnauld
6 hours ago
|
show 8 more comments
$begingroup$
Given a number 1≤n≤365, output the nth day of the year in "Day-numberth Month" format. For example, given 1, you should output "1st January", without "of".
The Gregorian calendar will be used and the program should not account for leap years, so your program should never output "29th February" in any circumstance. Any method can be used, as long as it follows the "Day-numberth Month" format mentioned before. Your program should also output ordinals correctly, meaning it should always output 1st, 2nd, 3rd, should 1, 2 or 3 respectively be the day numbers for any input. Leading spaces or other indentation are allowed.
This is code golf, so the shortest solution by characters wins.
Test cases:
1 gives 1st January
2 gives 2nd January
3 gives 3rd January
365 gives 31st December
60 gives 1st March
11 gives 11th January
code-golf date
$endgroup$
Given a number 1≤n≤365, output the nth day of the year in "Day-numberth Month" format. For example, given 1, you should output "1st January", without "of".
The Gregorian calendar will be used and the program should not account for leap years, so your program should never output "29th February" in any circumstance. Any method can be used, as long as it follows the "Day-numberth Month" format mentioned before. Your program should also output ordinals correctly, meaning it should always output 1st, 2nd, 3rd, should 1, 2 or 3 respectively be the day numbers for any input. Leading spaces or other indentation are allowed.
This is code golf, so the shortest solution by characters wins.
Test cases:
1 gives 1st January
2 gives 2nd January
3 gives 3rd January
365 gives 31st December
60 gives 1st March
11 gives 11th January
code-golf date
code-golf date
edited 5 hours ago
Andrew
asked 7 hours ago
AndrewAndrew
867
867
$begingroup$
What is "Day-number Month" format? I'm assuming it's "20th March"? Or is it "20 March"? That makes a pretty big difference, if you need ordinals.
$endgroup$
– Riker
7 hours ago
3
$begingroup$
Also, do you need to force an error message on numbers > 365? Can the program just assume that's invalid input and it won't need to handle that?
$endgroup$
– Riker
7 hours ago
4
$begingroup$
As not everyone is a native English speaker, you may want to add that day numbers 11, 12, and 13 get "th", numbers ending in "1" get "st", "2" get "nd", "3" get "rd", and all other get "th".
$endgroup$
– Adám
7 hours ago
4
$begingroup$
Whoa, don't accept answers so quickly. Especially not wrong answers!
$endgroup$
– Adám
6 hours ago
3
$begingroup$
You should add at least11
(11th January) and21
(21st January) to the test cases.
$endgroup$
– Arnauld
6 hours ago
|
show 8 more comments
$begingroup$
What is "Day-number Month" format? I'm assuming it's "20th March"? Or is it "20 March"? That makes a pretty big difference, if you need ordinals.
$endgroup$
– Riker
7 hours ago
3
$begingroup$
Also, do you need to force an error message on numbers > 365? Can the program just assume that's invalid input and it won't need to handle that?
$endgroup$
– Riker
7 hours ago
4
$begingroup$
As not everyone is a native English speaker, you may want to add that day numbers 11, 12, and 13 get "th", numbers ending in "1" get "st", "2" get "nd", "3" get "rd", and all other get "th".
$endgroup$
– Adám
7 hours ago
4
$begingroup$
Whoa, don't accept answers so quickly. Especially not wrong answers!
$endgroup$
– Adám
6 hours ago
3
$begingroup$
You should add at least11
(11th January) and21
(21st January) to the test cases.
$endgroup$
– Arnauld
6 hours ago
$begingroup$
What is "Day-number Month" format? I'm assuming it's "20th March"? Or is it "20 March"? That makes a pretty big difference, if you need ordinals.
$endgroup$
– Riker
7 hours ago
$begingroup$
What is "Day-number Month" format? I'm assuming it's "20th March"? Or is it "20 March"? That makes a pretty big difference, if you need ordinals.
$endgroup$
– Riker
7 hours ago
3
3
$begingroup$
Also, do you need to force an error message on numbers > 365? Can the program just assume that's invalid input and it won't need to handle that?
$endgroup$
– Riker
7 hours ago
$begingroup$
Also, do you need to force an error message on numbers > 365? Can the program just assume that's invalid input and it won't need to handle that?
$endgroup$
– Riker
7 hours ago
4
4
$begingroup$
As not everyone is a native English speaker, you may want to add that day numbers 11, 12, and 13 get "th", numbers ending in "1" get "st", "2" get "nd", "3" get "rd", and all other get "th".
$endgroup$
– Adám
7 hours ago
$begingroup$
As not everyone is a native English speaker, you may want to add that day numbers 11, 12, and 13 get "th", numbers ending in "1" get "st", "2" get "nd", "3" get "rd", and all other get "th".
$endgroup$
– Adám
7 hours ago
4
4
$begingroup$
Whoa, don't accept answers so quickly. Especially not wrong answers!
$endgroup$
– Adám
6 hours ago
$begingroup$
Whoa, don't accept answers so quickly. Especially not wrong answers!
$endgroup$
– Adám
6 hours ago
3
3
$begingroup$
You should add at least
11
(11th January) and 21
(21st January) to the test cases.$endgroup$
– Arnauld
6 hours ago
$begingroup$
You should add at least
11
(11th January) and 21
(21st January) to the test cases.$endgroup$
– Arnauld
6 hours ago
|
show 8 more comments
11 Answers
11
active
oldest
votes
$begingroup$
Google Sheets, 26 bytes
Thanks to my colleague Richard for spotting an error.
Takes input in cell A1.
=TEXT(1+A1,"d""th"" mmmm")
Try it online!
Google Sheets represents dates with 1 being 31st December 1899, so this adds one to the day number and formats appropriately.
The formula does not work in Microsoft Excel because it counter-factually calculates 1900 as a leap year.
$endgroup$
add a comment |
$begingroup$
Hack, 115 59 39 bytes
$x==>date("jS F",mktime(0,0,0,1,$x));
Since @gwaugh got to the same solution as mine while I was golfing, I'm posting this in Hack instead :).
$endgroup$
$begingroup$
Wow, great minds think alike. :) +1 to you sir!
$endgroup$
– gwaugh
6 hours ago
$begingroup$
@gwaugh haha, I didn't know I could just have a top-level program. I'll edit mine to make it top-level too, and find a way to get a better scor e;-)
$endgroup$
– Ven
6 hours ago
1
$begingroup$
@gwaugh Made mine Hack instead.
$endgroup$
– Ven
6 hours ago
$begingroup$
You'll probably want to specify a non-leap year parameter to yourmktime()
call otherwise it will return the wrong output if run on a leap year. (had to do to my answer).
$endgroup$
– gwaugh
6 hours ago
add a comment |
$begingroup$
Python 3.8 (pre-release), 112 bytes
lambda x:str(d:=(t:=gmtime(x*86399)).tm_mday)+'tsnrhtdd'[d%5*(d%30%20<4)::4]+strftime(' %B',t)
from time import*
Try it online!
Weirdly enough, I don't have to parenthesize d:=(t:=gmtime(~-x*86400)
, probably because the interpreter only checks if there are ()
characters around the assignment expression and not that the expression itself is parenthesized.
-2 thanks to gwaugh.
-5 thanks to xnor.
$endgroup$
$begingroup$
You can golf -2 bytes by changing~-x*86400
tox*86399
. tio.run/…
$endgroup$
– gwaugh
1 hour ago
$begingroup$
@gwaugh Hm, looks like that approximation does indeed work even for365
. :P
$endgroup$
– Erik the Outgolfer
1 hour ago
$begingroup$
You can shortend%10<4<8!=d&24
tod%30%20<4
.
$endgroup$
– xnor
30 mins ago
$begingroup$
@xnor Oh, duh! Thanks, was tired writing this...
$endgroup$
– Erik the Outgolfer
29 mins ago
add a comment |
$begingroup$
PHP, 38 40 30 28 bytes
<?=date("jS F",86399*$argn);
Try it online!
Run with php -nF
input is from STDIN
. Example (above script named y.php
):
$ echo 1|php -nF y.php
1st January
$ echo 2| php -nF y.php
2nd January
$ echo 3| php -nF y.php
3rd January
$ echo 11|php -nF y.php
11th January
$ echo 21|php -nF y.php
21st January
$ echo 60|php -nF y.php
1st March
$ echo 365|php -nF y.php
31st December
Explanation
Construct an epoch timestamp for the desired day in 1970 (conveniently not a leap year) by multiplying the day number * number of seconds per day
(86400). However, this would yield one day higher so instead multiply by number of seconds in a day - 1
(86399) which for the range of input numbers (1≤n≤365) will result with the timestamp of the end of each correct day. Then just use PHP's built-in date formatting for output.
$endgroup$
$begingroup$
why's the-n
necessary?
$endgroup$
– Ven
6 hours ago
$begingroup$
@Ven it might not be in all cases, but just disables any settings in local php.ini that might create inconsistent behavior.
$endgroup$
– gwaugh
6 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 117 bytes
d=>(n=(d=new Date(1,0,d)).getDate())+([,'st','nd','rd'][n%30%20]||'th')+' '+d.toLocaleDateString('en',{month:'long'})
Try it online!
Commented
d => // d = input day
( n = //
( d = // convert d to
new Date(1, 0, d) // a Date object for the non leap year 1901
).getDate() // save the corresponding day of month into n
) + ( //
[, 'st', 'nd', 'rd'] // ordinal suffixes
[n % 30 % 20] // map { 1, 2, 3, 21, 22, 23, 31 } to { 'st', 'nd', 'rd' }
|| 'th' // or use 'th' for everything else
) + ' ' + // append a space
d.toLocaleDateString( // convert d to ...
'en', // ... the English ...
{ month: 'long' } // ... month name
) //
Without date built-ins, 188 bytes
f=(d,m=0)=>d>(k=31-(1115212>>m*2&3))?f(d-k,m+1):d+([,'st','nd','rd'][d%30%20]||'th')+' '+`JanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecember`.match(/.[a-z]*/g)[m]
Try it online!
$endgroup$
$begingroup$
Fails for 11th,12th,13th of each month
$endgroup$
– Expired Data
6 hours ago
1
$begingroup$
@ExpiredData Thanks for reporting this. Fixed now.
$endgroup$
– Arnauld
6 hours ago
$begingroup$
Ignore my comment, I made an ID10T error.
$endgroup$
– asgallant
1 hour ago
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 141 139 133 124 122 bytes
a=>{var d=s.AddDays(a-1);int x=d.Day,m=x%30%20;return x+"thstndrd".Substring(m<4?m*2:0,2)+d.ToString(" MMMM");};DateTime s
Thanks to Arnauld for faster method of removing 11,12,13th saving 4 bytes
Try it online!
New contributor
$endgroup$
$begingroup$
Using C# 8, this can be reduced to:a=>{var d=s.AddDays(a-1);int x=d.Day,m=x%30%20;return x+"thstndrd"[(m<4?m*2:0)..2]+$" {d:MMMM}";};DateTime s
The interactive compiler doesn't seem to support changing its language level to "preview" at this time, though.
$endgroup$
– briman0094
3 hours ago
$begingroup$
116 bytes
$endgroup$
– Embodiment of Ignorance
2 hours ago
add a comment |
$begingroup$
Perl 6, 228 185 bytes
{$_>365&¨~Date.new(Date.new(Date.today.year,1,1).later(days=>$_),:formatter{.day~[0,"st","nd","rd",|("th"xx*)][.day%30%20]~' '~ [Date::Names.new.mon(.month)]})}(243)
Error checking costs 12 bytes.
AFAIK Perl 6 doesn't have month names built-in :. Not sure I'm allowed -MDate::Names
or not.
.later
is currently bugged on rakudo and drops the :formatter
, so I need to re-create a Date
on top with the correct formatter.
$endgroup$
$begingroup$
Yes, that's why I use.day%10
$endgroup$
– Ven
6 hours ago
1
$begingroup$
Doesn't[0,"st","nd","rd",|("th"xx*)][11%10]
lead to 11st? (My Perl skills are close to nil, so I may be missing something.)
$endgroup$
– Arnauld
6 hours ago
$begingroup$
Ah, right. I suppose%11 12 13
wouldn't work
$endgroup$
– Ven
6 hours ago
$begingroup$
I did the same mistake in my original answer and used%30%20
instead.
$endgroup$
– Arnauld
6 hours ago
$begingroup$
fixed that way then--ty
$endgroup$
– Ven
5 hours ago
|
show 1 more comment
$begingroup$
C# (Visual C# Interactive Compiler), 115 bytes
n=>{var g=p.AddDays(n-1);int f=g.Day,m=f%20%30<4?f%10:0;return f+$"{"tsnr"[m]+""+"htdd"[m]} {g:MMMM}";};DateTime p;
Try it online!
$endgroup$
add a comment |
$begingroup$
R, 158 134 bytes
-24 bytes @Nick Kennedy for golfing the 'st', 'nd', 'rd', & 'th'. Thanks!
f=format;paste0(a<-as.double(f(d<-as.Date(scan(,''),'%j'),'%e')),`if`((a-1)%%10>2|a%/%10==1,'th',c("st","nd","rd")[a%%10]),f(d,' %B'))
Try it online!
$endgroup$
$begingroup$
How about tio.run/##HYxBCsIwEEWvIoEwMzDVRldi40K8hQgdmwQV20oSd949xm4e/… for 134 bytes
$endgroup$
– Nick Kennedy
4 hours ago
$begingroup$
Yes, I need to learn`if`
better. Thanks.
$endgroup$
– CT Hall
2 hours ago
add a comment |
$begingroup$
Perl 6, 166 163 bytes
{.day~(<th st nd rd>[.day%30%20]||'th')~' '~ <January February March April May June July August September October November December>[.month-1]}o*+Date.new(1,1,1)-1
Try it online!
When you hardcode the month names, but still beat the previous Perl 6 answer that didn't >.<
$endgroup$
add a comment |
$begingroup$
Jelly, 115 114 bytes
’%⁵<3a:⁵n1Ɗ×%⁵$Ḥ+ؽị“thstndrd”ṭ
“5<Ḟ’b4+28ÄŻ_@µ>0T,>0$ƇZṪµ1ịị“1;8-UÞẆĊƬṁɱkzIṇkµ⁴ JḷJdɱ<©Q£Ƈ.dẊṘh!İḞẠƒĊ¶÷»Ỵ¤,2ịÇƊṚK
Try it online!
Long by Jelly standards, but done from first principles.
$endgroup$
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%2f181468%2fits-a-yearly-task-alright%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
11 Answers
11
active
oldest
votes
11 Answers
11
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Google Sheets, 26 bytes
Thanks to my colleague Richard for spotting an error.
Takes input in cell A1.
=TEXT(1+A1,"d""th"" mmmm")
Try it online!
Google Sheets represents dates with 1 being 31st December 1899, so this adds one to the day number and formats appropriately.
The formula does not work in Microsoft Excel because it counter-factually calculates 1900 as a leap year.
$endgroup$
add a comment |
$begingroup$
Google Sheets, 26 bytes
Thanks to my colleague Richard for spotting an error.
Takes input in cell A1.
=TEXT(1+A1,"d""th"" mmmm")
Try it online!
Google Sheets represents dates with 1 being 31st December 1899, so this adds one to the day number and formats appropriately.
The formula does not work in Microsoft Excel because it counter-factually calculates 1900 as a leap year.
$endgroup$
add a comment |
$begingroup$
Google Sheets, 26 bytes
Thanks to my colleague Richard for spotting an error.
Takes input in cell A1.
=TEXT(1+A1,"d""th"" mmmm")
Try it online!
Google Sheets represents dates with 1 being 31st December 1899, so this adds one to the day number and formats appropriately.
The formula does not work in Microsoft Excel because it counter-factually calculates 1900 as a leap year.
$endgroup$
Google Sheets, 26 bytes
Thanks to my colleague Richard for spotting an error.
Takes input in cell A1.
=TEXT(1+A1,"d""th"" mmmm")
Try it online!
Google Sheets represents dates with 1 being 31st December 1899, so this adds one to the day number and formats appropriately.
The formula does not work in Microsoft Excel because it counter-factually calculates 1900 as a leap year.
edited 6 hours ago
answered 7 hours ago
AdámAdám
28.8k276204
28.8k276204
add a comment |
add a comment |
$begingroup$
Hack, 115 59 39 bytes
$x==>date("jS F",mktime(0,0,0,1,$x));
Since @gwaugh got to the same solution as mine while I was golfing, I'm posting this in Hack instead :).
$endgroup$
$begingroup$
Wow, great minds think alike. :) +1 to you sir!
$endgroup$
– gwaugh
6 hours ago
$begingroup$
@gwaugh haha, I didn't know I could just have a top-level program. I'll edit mine to make it top-level too, and find a way to get a better scor e;-)
$endgroup$
– Ven
6 hours ago
1
$begingroup$
@gwaugh Made mine Hack instead.
$endgroup$
– Ven
6 hours ago
$begingroup$
You'll probably want to specify a non-leap year parameter to yourmktime()
call otherwise it will return the wrong output if run on a leap year. (had to do to my answer).
$endgroup$
– gwaugh
6 hours ago
add a comment |
$begingroup$
Hack, 115 59 39 bytes
$x==>date("jS F",mktime(0,0,0,1,$x));
Since @gwaugh got to the same solution as mine while I was golfing, I'm posting this in Hack instead :).
$endgroup$
$begingroup$
Wow, great minds think alike. :) +1 to you sir!
$endgroup$
– gwaugh
6 hours ago
$begingroup$
@gwaugh haha, I didn't know I could just have a top-level program. I'll edit mine to make it top-level too, and find a way to get a better scor e;-)
$endgroup$
– Ven
6 hours ago
1
$begingroup$
@gwaugh Made mine Hack instead.
$endgroup$
– Ven
6 hours ago
$begingroup$
You'll probably want to specify a non-leap year parameter to yourmktime()
call otherwise it will return the wrong output if run on a leap year. (had to do to my answer).
$endgroup$
– gwaugh
6 hours ago
add a comment |
$begingroup$
Hack, 115 59 39 bytes
$x==>date("jS F",mktime(0,0,0,1,$x));
Since @gwaugh got to the same solution as mine while I was golfing, I'm posting this in Hack instead :).
$endgroup$
Hack, 115 59 39 bytes
$x==>date("jS F",mktime(0,0,0,1,$x));
Since @gwaugh got to the same solution as mine while I was golfing, I'm posting this in Hack instead :).
edited 6 hours ago
answered 6 hours ago
VenVen
2,32511123
2,32511123
$begingroup$
Wow, great minds think alike. :) +1 to you sir!
$endgroup$
– gwaugh
6 hours ago
$begingroup$
@gwaugh haha, I didn't know I could just have a top-level program. I'll edit mine to make it top-level too, and find a way to get a better scor e;-)
$endgroup$
– Ven
6 hours ago
1
$begingroup$
@gwaugh Made mine Hack instead.
$endgroup$
– Ven
6 hours ago
$begingroup$
You'll probably want to specify a non-leap year parameter to yourmktime()
call otherwise it will return the wrong output if run on a leap year. (had to do to my answer).
$endgroup$
– gwaugh
6 hours ago
add a comment |
$begingroup$
Wow, great minds think alike. :) +1 to you sir!
$endgroup$
– gwaugh
6 hours ago
$begingroup$
@gwaugh haha, I didn't know I could just have a top-level program. I'll edit mine to make it top-level too, and find a way to get a better scor e;-)
$endgroup$
– Ven
6 hours ago
1
$begingroup$
@gwaugh Made mine Hack instead.
$endgroup$
– Ven
6 hours ago
$begingroup$
You'll probably want to specify a non-leap year parameter to yourmktime()
call otherwise it will return the wrong output if run on a leap year. (had to do to my answer).
$endgroup$
– gwaugh
6 hours ago
$begingroup$
Wow, great minds think alike. :) +1 to you sir!
$endgroup$
– gwaugh
6 hours ago
$begingroup$
Wow, great minds think alike. :) +1 to you sir!
$endgroup$
– gwaugh
6 hours ago
$begingroup$
@gwaugh haha, I didn't know I could just have a top-level program. I'll edit mine to make it top-level too, and find a way to get a better scor e;-)
$endgroup$
– Ven
6 hours ago
$begingroup$
@gwaugh haha, I didn't know I could just have a top-level program. I'll edit mine to make it top-level too, and find a way to get a better scor e;-)
$endgroup$
– Ven
6 hours ago
1
1
$begingroup$
@gwaugh Made mine Hack instead.
$endgroup$
– Ven
6 hours ago
$begingroup$
@gwaugh Made mine Hack instead.
$endgroup$
– Ven
6 hours ago
$begingroup$
You'll probably want to specify a non-leap year parameter to your
mktime()
call otherwise it will return the wrong output if run on a leap year. (had to do to my answer).$endgroup$
– gwaugh
6 hours ago
$begingroup$
You'll probably want to specify a non-leap year parameter to your
mktime()
call otherwise it will return the wrong output if run on a leap year. (had to do to my answer).$endgroup$
– gwaugh
6 hours ago
add a comment |
$begingroup$
Python 3.8 (pre-release), 112 bytes
lambda x:str(d:=(t:=gmtime(x*86399)).tm_mday)+'tsnrhtdd'[d%5*(d%30%20<4)::4]+strftime(' %B',t)
from time import*
Try it online!
Weirdly enough, I don't have to parenthesize d:=(t:=gmtime(~-x*86400)
, probably because the interpreter only checks if there are ()
characters around the assignment expression and not that the expression itself is parenthesized.
-2 thanks to gwaugh.
-5 thanks to xnor.
$endgroup$
$begingroup$
You can golf -2 bytes by changing~-x*86400
tox*86399
. tio.run/…
$endgroup$
– gwaugh
1 hour ago
$begingroup$
@gwaugh Hm, looks like that approximation does indeed work even for365
. :P
$endgroup$
– Erik the Outgolfer
1 hour ago
$begingroup$
You can shortend%10<4<8!=d&24
tod%30%20<4
.
$endgroup$
– xnor
30 mins ago
$begingroup$
@xnor Oh, duh! Thanks, was tired writing this...
$endgroup$
– Erik the Outgolfer
29 mins ago
add a comment |
$begingroup$
Python 3.8 (pre-release), 112 bytes
lambda x:str(d:=(t:=gmtime(x*86399)).tm_mday)+'tsnrhtdd'[d%5*(d%30%20<4)::4]+strftime(' %B',t)
from time import*
Try it online!
Weirdly enough, I don't have to parenthesize d:=(t:=gmtime(~-x*86400)
, probably because the interpreter only checks if there are ()
characters around the assignment expression and not that the expression itself is parenthesized.
-2 thanks to gwaugh.
-5 thanks to xnor.
$endgroup$
$begingroup$
You can golf -2 bytes by changing~-x*86400
tox*86399
. tio.run/…
$endgroup$
– gwaugh
1 hour ago
$begingroup$
@gwaugh Hm, looks like that approximation does indeed work even for365
. :P
$endgroup$
– Erik the Outgolfer
1 hour ago
$begingroup$
You can shortend%10<4<8!=d&24
tod%30%20<4
.
$endgroup$
– xnor
30 mins ago
$begingroup$
@xnor Oh, duh! Thanks, was tired writing this...
$endgroup$
– Erik the Outgolfer
29 mins ago
add a comment |
$begingroup$
Python 3.8 (pre-release), 112 bytes
lambda x:str(d:=(t:=gmtime(x*86399)).tm_mday)+'tsnrhtdd'[d%5*(d%30%20<4)::4]+strftime(' %B',t)
from time import*
Try it online!
Weirdly enough, I don't have to parenthesize d:=(t:=gmtime(~-x*86400)
, probably because the interpreter only checks if there are ()
characters around the assignment expression and not that the expression itself is parenthesized.
-2 thanks to gwaugh.
-5 thanks to xnor.
$endgroup$
Python 3.8 (pre-release), 112 bytes
lambda x:str(d:=(t:=gmtime(x*86399)).tm_mday)+'tsnrhtdd'[d%5*(d%30%20<4)::4]+strftime(' %B',t)
from time import*
Try it online!
Weirdly enough, I don't have to parenthesize d:=(t:=gmtime(~-x*86400)
, probably because the interpreter only checks if there are ()
characters around the assignment expression and not that the expression itself is parenthesized.
-2 thanks to gwaugh.
-5 thanks to xnor.
edited 28 mins ago
answered 2 hours ago
Erik the OutgolferErik the Outgolfer
32.4k429105
32.4k429105
$begingroup$
You can golf -2 bytes by changing~-x*86400
tox*86399
. tio.run/…
$endgroup$
– gwaugh
1 hour ago
$begingroup$
@gwaugh Hm, looks like that approximation does indeed work even for365
. :P
$endgroup$
– Erik the Outgolfer
1 hour ago
$begingroup$
You can shortend%10<4<8!=d&24
tod%30%20<4
.
$endgroup$
– xnor
30 mins ago
$begingroup$
@xnor Oh, duh! Thanks, was tired writing this...
$endgroup$
– Erik the Outgolfer
29 mins ago
add a comment |
$begingroup$
You can golf -2 bytes by changing~-x*86400
tox*86399
. tio.run/…
$endgroup$
– gwaugh
1 hour ago
$begingroup$
@gwaugh Hm, looks like that approximation does indeed work even for365
. :P
$endgroup$
– Erik the Outgolfer
1 hour ago
$begingroup$
You can shortend%10<4<8!=d&24
tod%30%20<4
.
$endgroup$
– xnor
30 mins ago
$begingroup$
@xnor Oh, duh! Thanks, was tired writing this...
$endgroup$
– Erik the Outgolfer
29 mins ago
$begingroup$
You can golf -2 bytes by changing
~-x*86400
to x*86399
. tio.run/…$endgroup$
– gwaugh
1 hour ago
$begingroup$
You can golf -2 bytes by changing
~-x*86400
to x*86399
. tio.run/…$endgroup$
– gwaugh
1 hour ago
$begingroup$
@gwaugh Hm, looks like that approximation does indeed work even for
365
. :P$endgroup$
– Erik the Outgolfer
1 hour ago
$begingroup$
@gwaugh Hm, looks like that approximation does indeed work even for
365
. :P$endgroup$
– Erik the Outgolfer
1 hour ago
$begingroup$
You can shorten
d%10<4<8!=d&24
to d%30%20<4
.$endgroup$
– xnor
30 mins ago
$begingroup$
You can shorten
d%10<4<8!=d&24
to d%30%20<4
.$endgroup$
– xnor
30 mins ago
$begingroup$
@xnor Oh, duh! Thanks, was tired writing this...
$endgroup$
– Erik the Outgolfer
29 mins ago
$begingroup$
@xnor Oh, duh! Thanks, was tired writing this...
$endgroup$
– Erik the Outgolfer
29 mins ago
add a comment |
$begingroup$
PHP, 38 40 30 28 bytes
<?=date("jS F",86399*$argn);
Try it online!
Run with php -nF
input is from STDIN
. Example (above script named y.php
):
$ echo 1|php -nF y.php
1st January
$ echo 2| php -nF y.php
2nd January
$ echo 3| php -nF y.php
3rd January
$ echo 11|php -nF y.php
11th January
$ echo 21|php -nF y.php
21st January
$ echo 60|php -nF y.php
1st March
$ echo 365|php -nF y.php
31st December
Explanation
Construct an epoch timestamp for the desired day in 1970 (conveniently not a leap year) by multiplying the day number * number of seconds per day
(86400). However, this would yield one day higher so instead multiply by number of seconds in a day - 1
(86399) which for the range of input numbers (1≤n≤365) will result with the timestamp of the end of each correct day. Then just use PHP's built-in date formatting for output.
$endgroup$
$begingroup$
why's the-n
necessary?
$endgroup$
– Ven
6 hours ago
$begingroup$
@Ven it might not be in all cases, but just disables any settings in local php.ini that might create inconsistent behavior.
$endgroup$
– gwaugh
6 hours ago
add a comment |
$begingroup$
PHP, 38 40 30 28 bytes
<?=date("jS F",86399*$argn);
Try it online!
Run with php -nF
input is from STDIN
. Example (above script named y.php
):
$ echo 1|php -nF y.php
1st January
$ echo 2| php -nF y.php
2nd January
$ echo 3| php -nF y.php
3rd January
$ echo 11|php -nF y.php
11th January
$ echo 21|php -nF y.php
21st January
$ echo 60|php -nF y.php
1st March
$ echo 365|php -nF y.php
31st December
Explanation
Construct an epoch timestamp for the desired day in 1970 (conveniently not a leap year) by multiplying the day number * number of seconds per day
(86400). However, this would yield one day higher so instead multiply by number of seconds in a day - 1
(86399) which for the range of input numbers (1≤n≤365) will result with the timestamp of the end of each correct day. Then just use PHP's built-in date formatting for output.
$endgroup$
$begingroup$
why's the-n
necessary?
$endgroup$
– Ven
6 hours ago
$begingroup$
@Ven it might not be in all cases, but just disables any settings in local php.ini that might create inconsistent behavior.
$endgroup$
– gwaugh
6 hours ago
add a comment |
$begingroup$
PHP, 38 40 30 28 bytes
<?=date("jS F",86399*$argn);
Try it online!
Run with php -nF
input is from STDIN
. Example (above script named y.php
):
$ echo 1|php -nF y.php
1st January
$ echo 2| php -nF y.php
2nd January
$ echo 3| php -nF y.php
3rd January
$ echo 11|php -nF y.php
11th January
$ echo 21|php -nF y.php
21st January
$ echo 60|php -nF y.php
1st March
$ echo 365|php -nF y.php
31st December
Explanation
Construct an epoch timestamp for the desired day in 1970 (conveniently not a leap year) by multiplying the day number * number of seconds per day
(86400). However, this would yield one day higher so instead multiply by number of seconds in a day - 1
(86399) which for the range of input numbers (1≤n≤365) will result with the timestamp of the end of each correct day. Then just use PHP's built-in date formatting for output.
$endgroup$
PHP, 38 40 30 28 bytes
<?=date("jS F",86399*$argn);
Try it online!
Run with php -nF
input is from STDIN
. Example (above script named y.php
):
$ echo 1|php -nF y.php
1st January
$ echo 2| php -nF y.php
2nd January
$ echo 3| php -nF y.php
3rd January
$ echo 11|php -nF y.php
11th January
$ echo 21|php -nF y.php
21st January
$ echo 60|php -nF y.php
1st March
$ echo 365|php -nF y.php
31st December
Explanation
Construct an epoch timestamp for the desired day in 1970 (conveniently not a leap year) by multiplying the day number * number of seconds per day
(86400). However, this would yield one day higher so instead multiply by number of seconds in a day - 1
(86399) which for the range of input numbers (1≤n≤365) will result with the timestamp of the end of each correct day. Then just use PHP's built-in date formatting for output.
edited 4 hours ago
answered 6 hours ago
gwaughgwaugh
1,613515
1,613515
$begingroup$
why's the-n
necessary?
$endgroup$
– Ven
6 hours ago
$begingroup$
@Ven it might not be in all cases, but just disables any settings in local php.ini that might create inconsistent behavior.
$endgroup$
– gwaugh
6 hours ago
add a comment |
$begingroup$
why's the-n
necessary?
$endgroup$
– Ven
6 hours ago
$begingroup$
@Ven it might not be in all cases, but just disables any settings in local php.ini that might create inconsistent behavior.
$endgroup$
– gwaugh
6 hours ago
$begingroup$
why's the
-n
necessary?$endgroup$
– Ven
6 hours ago
$begingroup$
why's the
-n
necessary?$endgroup$
– Ven
6 hours ago
$begingroup$
@Ven it might not be in all cases, but just disables any settings in local php.ini that might create inconsistent behavior.
$endgroup$
– gwaugh
6 hours ago
$begingroup$
@Ven it might not be in all cases, but just disables any settings in local php.ini that might create inconsistent behavior.
$endgroup$
– gwaugh
6 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 117 bytes
d=>(n=(d=new Date(1,0,d)).getDate())+([,'st','nd','rd'][n%30%20]||'th')+' '+d.toLocaleDateString('en',{month:'long'})
Try it online!
Commented
d => // d = input day
( n = //
( d = // convert d to
new Date(1, 0, d) // a Date object for the non leap year 1901
).getDate() // save the corresponding day of month into n
) + ( //
[, 'st', 'nd', 'rd'] // ordinal suffixes
[n % 30 % 20] // map { 1, 2, 3, 21, 22, 23, 31 } to { 'st', 'nd', 'rd' }
|| 'th' // or use 'th' for everything else
) + ' ' + // append a space
d.toLocaleDateString( // convert d to ...
'en', // ... the English ...
{ month: 'long' } // ... month name
) //
Without date built-ins, 188 bytes
f=(d,m=0)=>d>(k=31-(1115212>>m*2&3))?f(d-k,m+1):d+([,'st','nd','rd'][d%30%20]||'th')+' '+`JanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecember`.match(/.[a-z]*/g)[m]
Try it online!
$endgroup$
$begingroup$
Fails for 11th,12th,13th of each month
$endgroup$
– Expired Data
6 hours ago
1
$begingroup$
@ExpiredData Thanks for reporting this. Fixed now.
$endgroup$
– Arnauld
6 hours ago
$begingroup$
Ignore my comment, I made an ID10T error.
$endgroup$
– asgallant
1 hour ago
add a comment |
$begingroup$
JavaScript (ES6), 117 bytes
d=>(n=(d=new Date(1,0,d)).getDate())+([,'st','nd','rd'][n%30%20]||'th')+' '+d.toLocaleDateString('en',{month:'long'})
Try it online!
Commented
d => // d = input day
( n = //
( d = // convert d to
new Date(1, 0, d) // a Date object for the non leap year 1901
).getDate() // save the corresponding day of month into n
) + ( //
[, 'st', 'nd', 'rd'] // ordinal suffixes
[n % 30 % 20] // map { 1, 2, 3, 21, 22, 23, 31 } to { 'st', 'nd', 'rd' }
|| 'th' // or use 'th' for everything else
) + ' ' + // append a space
d.toLocaleDateString( // convert d to ...
'en', // ... the English ...
{ month: 'long' } // ... month name
) //
Without date built-ins, 188 bytes
f=(d,m=0)=>d>(k=31-(1115212>>m*2&3))?f(d-k,m+1):d+([,'st','nd','rd'][d%30%20]||'th')+' '+`JanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecember`.match(/.[a-z]*/g)[m]
Try it online!
$endgroup$
$begingroup$
Fails for 11th,12th,13th of each month
$endgroup$
– Expired Data
6 hours ago
1
$begingroup$
@ExpiredData Thanks for reporting this. Fixed now.
$endgroup$
– Arnauld
6 hours ago
$begingroup$
Ignore my comment, I made an ID10T error.
$endgroup$
– asgallant
1 hour ago
add a comment |
$begingroup$
JavaScript (ES6), 117 bytes
d=>(n=(d=new Date(1,0,d)).getDate())+([,'st','nd','rd'][n%30%20]||'th')+' '+d.toLocaleDateString('en',{month:'long'})
Try it online!
Commented
d => // d = input day
( n = //
( d = // convert d to
new Date(1, 0, d) // a Date object for the non leap year 1901
).getDate() // save the corresponding day of month into n
) + ( //
[, 'st', 'nd', 'rd'] // ordinal suffixes
[n % 30 % 20] // map { 1, 2, 3, 21, 22, 23, 31 } to { 'st', 'nd', 'rd' }
|| 'th' // or use 'th' for everything else
) + ' ' + // append a space
d.toLocaleDateString( // convert d to ...
'en', // ... the English ...
{ month: 'long' } // ... month name
) //
Without date built-ins, 188 bytes
f=(d,m=0)=>d>(k=31-(1115212>>m*2&3))?f(d-k,m+1):d+([,'st','nd','rd'][d%30%20]||'th')+' '+`JanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecember`.match(/.[a-z]*/g)[m]
Try it online!
$endgroup$
JavaScript (ES6), 117 bytes
d=>(n=(d=new Date(1,0,d)).getDate())+([,'st','nd','rd'][n%30%20]||'th')+' '+d.toLocaleDateString('en',{month:'long'})
Try it online!
Commented
d => // d = input day
( n = //
( d = // convert d to
new Date(1, 0, d) // a Date object for the non leap year 1901
).getDate() // save the corresponding day of month into n
) + ( //
[, 'st', 'nd', 'rd'] // ordinal suffixes
[n % 30 % 20] // map { 1, 2, 3, 21, 22, 23, 31 } to { 'st', 'nd', 'rd' }
|| 'th' // or use 'th' for everything else
) + ' ' + // append a space
d.toLocaleDateString( // convert d to ...
'en', // ... the English ...
{ month: 'long' } // ... month name
) //
Without date built-ins, 188 bytes
f=(d,m=0)=>d>(k=31-(1115212>>m*2&3))?f(d-k,m+1):d+([,'st','nd','rd'][d%30%20]||'th')+' '+`JanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecember`.match(/.[a-z]*/g)[m]
Try it online!
edited 3 hours ago
answered 6 hours ago
ArnauldArnauld
78.6k795327
78.6k795327
$begingroup$
Fails for 11th,12th,13th of each month
$endgroup$
– Expired Data
6 hours ago
1
$begingroup$
@ExpiredData Thanks for reporting this. Fixed now.
$endgroup$
– Arnauld
6 hours ago
$begingroup$
Ignore my comment, I made an ID10T error.
$endgroup$
– asgallant
1 hour ago
add a comment |
$begingroup$
Fails for 11th,12th,13th of each month
$endgroup$
– Expired Data
6 hours ago
1
$begingroup$
@ExpiredData Thanks for reporting this. Fixed now.
$endgroup$
– Arnauld
6 hours ago
$begingroup$
Ignore my comment, I made an ID10T error.
$endgroup$
– asgallant
1 hour ago
$begingroup$
Fails for 11th,12th,13th of each month
$endgroup$
– Expired Data
6 hours ago
$begingroup$
Fails for 11th,12th,13th of each month
$endgroup$
– Expired Data
6 hours ago
1
1
$begingroup$
@ExpiredData Thanks for reporting this. Fixed now.
$endgroup$
– Arnauld
6 hours ago
$begingroup$
@ExpiredData Thanks for reporting this. Fixed now.
$endgroup$
– Arnauld
6 hours ago
$begingroup$
Ignore my comment, I made an ID10T error.
$endgroup$
– asgallant
1 hour ago
$begingroup$
Ignore my comment, I made an ID10T error.
$endgroup$
– asgallant
1 hour ago
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 141 139 133 124 122 bytes
a=>{var d=s.AddDays(a-1);int x=d.Day,m=x%30%20;return x+"thstndrd".Substring(m<4?m*2:0,2)+d.ToString(" MMMM");};DateTime s
Thanks to Arnauld for faster method of removing 11,12,13th saving 4 bytes
Try it online!
New contributor
$endgroup$
$begingroup$
Using C# 8, this can be reduced to:a=>{var d=s.AddDays(a-1);int x=d.Day,m=x%30%20;return x+"thstndrd"[(m<4?m*2:0)..2]+$" {d:MMMM}";};DateTime s
The interactive compiler doesn't seem to support changing its language level to "preview" at this time, though.
$endgroup$
– briman0094
3 hours ago
$begingroup$
116 bytes
$endgroup$
– Embodiment of Ignorance
2 hours ago
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 141 139 133 124 122 bytes
a=>{var d=s.AddDays(a-1);int x=d.Day,m=x%30%20;return x+"thstndrd".Substring(m<4?m*2:0,2)+d.ToString(" MMMM");};DateTime s
Thanks to Arnauld for faster method of removing 11,12,13th saving 4 bytes
Try it online!
New contributor
$endgroup$
$begingroup$
Using C# 8, this can be reduced to:a=>{var d=s.AddDays(a-1);int x=d.Day,m=x%30%20;return x+"thstndrd"[(m<4?m*2:0)..2]+$" {d:MMMM}";};DateTime s
The interactive compiler doesn't seem to support changing its language level to "preview" at this time, though.
$endgroup$
– briman0094
3 hours ago
$begingroup$
116 bytes
$endgroup$
– Embodiment of Ignorance
2 hours ago
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 141 139 133 124 122 bytes
a=>{var d=s.AddDays(a-1);int x=d.Day,m=x%30%20;return x+"thstndrd".Substring(m<4?m*2:0,2)+d.ToString(" MMMM");};DateTime s
Thanks to Arnauld for faster method of removing 11,12,13th saving 4 bytes
Try it online!
New contributor
$endgroup$
C# (Visual C# Interactive Compiler), 141 139 133 124 122 bytes
a=>{var d=s.AddDays(a-1);int x=d.Day,m=x%30%20;return x+"thstndrd".Substring(m<4?m*2:0,2)+d.ToString(" MMMM");};DateTime s
Thanks to Arnauld for faster method of removing 11,12,13th saving 4 bytes
Try it online!
New contributor
edited 5 hours ago
New contributor
answered 6 hours ago
Expired DataExpired Data
1113
1113
New contributor
New contributor
$begingroup$
Using C# 8, this can be reduced to:a=>{var d=s.AddDays(a-1);int x=d.Day,m=x%30%20;return x+"thstndrd"[(m<4?m*2:0)..2]+$" {d:MMMM}";};DateTime s
The interactive compiler doesn't seem to support changing its language level to "preview" at this time, though.
$endgroup$
– briman0094
3 hours ago
$begingroup$
116 bytes
$endgroup$
– Embodiment of Ignorance
2 hours ago
add a comment |
$begingroup$
Using C# 8, this can be reduced to:a=>{var d=s.AddDays(a-1);int x=d.Day,m=x%30%20;return x+"thstndrd"[(m<4?m*2:0)..2]+$" {d:MMMM}";};DateTime s
The interactive compiler doesn't seem to support changing its language level to "preview" at this time, though.
$endgroup$
– briman0094
3 hours ago
$begingroup$
116 bytes
$endgroup$
– Embodiment of Ignorance
2 hours ago
$begingroup$
Using C# 8, this can be reduced to:
a=>{var d=s.AddDays(a-1);int x=d.Day,m=x%30%20;return x+"thstndrd"[(m<4?m*2:0)..2]+$" {d:MMMM}";};DateTime s
The interactive compiler doesn't seem to support changing its language level to "preview" at this time, though.$endgroup$
– briman0094
3 hours ago
$begingroup$
Using C# 8, this can be reduced to:
a=>{var d=s.AddDays(a-1);int x=d.Day,m=x%30%20;return x+"thstndrd"[(m<4?m*2:0)..2]+$" {d:MMMM}";};DateTime s
The interactive compiler doesn't seem to support changing its language level to "preview" at this time, though.$endgroup$
– briman0094
3 hours ago
$begingroup$
116 bytes
$endgroup$
– Embodiment of Ignorance
2 hours ago
$begingroup$
116 bytes
$endgroup$
– Embodiment of Ignorance
2 hours ago
add a comment |
$begingroup$
Perl 6, 228 185 bytes
{$_>365&¨~Date.new(Date.new(Date.today.year,1,1).later(days=>$_),:formatter{.day~[0,"st","nd","rd",|("th"xx*)][.day%30%20]~' '~ [Date::Names.new.mon(.month)]})}(243)
Error checking costs 12 bytes.
AFAIK Perl 6 doesn't have month names built-in :. Not sure I'm allowed -MDate::Names
or not.
.later
is currently bugged on rakudo and drops the :formatter
, so I need to re-create a Date
on top with the correct formatter.
$endgroup$
$begingroup$
Yes, that's why I use.day%10
$endgroup$
– Ven
6 hours ago
1
$begingroup$
Doesn't[0,"st","nd","rd",|("th"xx*)][11%10]
lead to 11st? (My Perl skills are close to nil, so I may be missing something.)
$endgroup$
– Arnauld
6 hours ago
$begingroup$
Ah, right. I suppose%11 12 13
wouldn't work
$endgroup$
– Ven
6 hours ago
$begingroup$
I did the same mistake in my original answer and used%30%20
instead.
$endgroup$
– Arnauld
6 hours ago
$begingroup$
fixed that way then--ty
$endgroup$
– Ven
5 hours ago
|
show 1 more comment
$begingroup$
Perl 6, 228 185 bytes
{$_>365&¨~Date.new(Date.new(Date.today.year,1,1).later(days=>$_),:formatter{.day~[0,"st","nd","rd",|("th"xx*)][.day%30%20]~' '~ [Date::Names.new.mon(.month)]})}(243)
Error checking costs 12 bytes.
AFAIK Perl 6 doesn't have month names built-in :. Not sure I'm allowed -MDate::Names
or not.
.later
is currently bugged on rakudo and drops the :formatter
, so I need to re-create a Date
on top with the correct formatter.
$endgroup$
$begingroup$
Yes, that's why I use.day%10
$endgroup$
– Ven
6 hours ago
1
$begingroup$
Doesn't[0,"st","nd","rd",|("th"xx*)][11%10]
lead to 11st? (My Perl skills are close to nil, so I may be missing something.)
$endgroup$
– Arnauld
6 hours ago
$begingroup$
Ah, right. I suppose%11 12 13
wouldn't work
$endgroup$
– Ven
6 hours ago
$begingroup$
I did the same mistake in my original answer and used%30%20
instead.
$endgroup$
– Arnauld
6 hours ago
$begingroup$
fixed that way then--ty
$endgroup$
– Ven
5 hours ago
|
show 1 more comment
$begingroup$
Perl 6, 228 185 bytes
{$_>365&¨~Date.new(Date.new(Date.today.year,1,1).later(days=>$_),:formatter{.day~[0,"st","nd","rd",|("th"xx*)][.day%30%20]~' '~ [Date::Names.new.mon(.month)]})}(243)
Error checking costs 12 bytes.
AFAIK Perl 6 doesn't have month names built-in :. Not sure I'm allowed -MDate::Names
or not.
.later
is currently bugged on rakudo and drops the :formatter
, so I need to re-create a Date
on top with the correct formatter.
$endgroup$
Perl 6, 228 185 bytes
{$_>365&¨~Date.new(Date.new(Date.today.year,1,1).later(days=>$_),:formatter{.day~[0,"st","nd","rd",|("th"xx*)][.day%30%20]~' '~ [Date::Names.new.mon(.month)]})}(243)
Error checking costs 12 bytes.
AFAIK Perl 6 doesn't have month names built-in :. Not sure I'm allowed -MDate::Names
or not.
.later
is currently bugged on rakudo and drops the :formatter
, so I need to re-create a Date
on top with the correct formatter.
edited 5 hours ago
answered 6 hours ago
VenVen
2,32511123
2,32511123
$begingroup$
Yes, that's why I use.day%10
$endgroup$
– Ven
6 hours ago
1
$begingroup$
Doesn't[0,"st","nd","rd",|("th"xx*)][11%10]
lead to 11st? (My Perl skills are close to nil, so I may be missing something.)
$endgroup$
– Arnauld
6 hours ago
$begingroup$
Ah, right. I suppose%11 12 13
wouldn't work
$endgroup$
– Ven
6 hours ago
$begingroup$
I did the same mistake in my original answer and used%30%20
instead.
$endgroup$
– Arnauld
6 hours ago
$begingroup$
fixed that way then--ty
$endgroup$
– Ven
5 hours ago
|
show 1 more comment
$begingroup$
Yes, that's why I use.day%10
$endgroup$
– Ven
6 hours ago
1
$begingroup$
Doesn't[0,"st","nd","rd",|("th"xx*)][11%10]
lead to 11st? (My Perl skills are close to nil, so I may be missing something.)
$endgroup$
– Arnauld
6 hours ago
$begingroup$
Ah, right. I suppose%11 12 13
wouldn't work
$endgroup$
– Ven
6 hours ago
$begingroup$
I did the same mistake in my original answer and used%30%20
instead.
$endgroup$
– Arnauld
6 hours ago
$begingroup$
fixed that way then--ty
$endgroup$
– Ven
5 hours ago
$begingroup$
Yes, that's why I use
.day%10
$endgroup$
– Ven
6 hours ago
$begingroup$
Yes, that's why I use
.day%10
$endgroup$
– Ven
6 hours ago
1
1
$begingroup$
Doesn't
[0,"st","nd","rd",|("th"xx*)][11%10]
lead to 11st? (My Perl skills are close to nil, so I may be missing something.)$endgroup$
– Arnauld
6 hours ago
$begingroup$
Doesn't
[0,"st","nd","rd",|("th"xx*)][11%10]
lead to 11st? (My Perl skills are close to nil, so I may be missing something.)$endgroup$
– Arnauld
6 hours ago
$begingroup$
Ah, right. I suppose
%11 12 13
wouldn't work$endgroup$
– Ven
6 hours ago
$begingroup$
Ah, right. I suppose
%11 12 13
wouldn't work$endgroup$
– Ven
6 hours ago
$begingroup$
I did the same mistake in my original answer and used
%30%20
instead.$endgroup$
– Arnauld
6 hours ago
$begingroup$
I did the same mistake in my original answer and used
%30%20
instead.$endgroup$
– Arnauld
6 hours ago
$begingroup$
fixed that way then--ty
$endgroup$
– Ven
5 hours ago
$begingroup$
fixed that way then--ty
$endgroup$
– Ven
5 hours ago
|
show 1 more comment
$begingroup$
C# (Visual C# Interactive Compiler), 115 bytes
n=>{var g=p.AddDays(n-1);int f=g.Day,m=f%20%30<4?f%10:0;return f+$"{"tsnr"[m]+""+"htdd"[m]} {g:MMMM}";};DateTime p;
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 115 bytes
n=>{var g=p.AddDays(n-1);int f=g.Day,m=f%20%30<4?f%10:0;return f+$"{"tsnr"[m]+""+"htdd"[m]} {g:MMMM}";};DateTime p;
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 115 bytes
n=>{var g=p.AddDays(n-1);int f=g.Day,m=f%20%30<4?f%10:0;return f+$"{"tsnr"[m]+""+"htdd"[m]} {g:MMMM}";};DateTime p;
Try it online!
$endgroup$
C# (Visual C# Interactive Compiler), 115 bytes
n=>{var g=p.AddDays(n-1);int f=g.Day,m=f%20%30<4?f%10:0;return f+$"{"tsnr"[m]+""+"htdd"[m]} {g:MMMM}";};DateTime p;
Try it online!
edited 2 hours ago
answered 2 hours ago
Embodiment of IgnoranceEmbodiment of Ignorance
1,688124
1,688124
add a comment |
add a comment |
$begingroup$
R, 158 134 bytes
-24 bytes @Nick Kennedy for golfing the 'st', 'nd', 'rd', & 'th'. Thanks!
f=format;paste0(a<-as.double(f(d<-as.Date(scan(,''),'%j'),'%e')),`if`((a-1)%%10>2|a%/%10==1,'th',c("st","nd","rd")[a%%10]),f(d,' %B'))
Try it online!
$endgroup$
$begingroup$
How about tio.run/##HYxBCsIwEEWvIoEwMzDVRldi40K8hQgdmwQV20oSd949xm4e/… for 134 bytes
$endgroup$
– Nick Kennedy
4 hours ago
$begingroup$
Yes, I need to learn`if`
better. Thanks.
$endgroup$
– CT Hall
2 hours ago
add a comment |
$begingroup$
R, 158 134 bytes
-24 bytes @Nick Kennedy for golfing the 'st', 'nd', 'rd', & 'th'. Thanks!
f=format;paste0(a<-as.double(f(d<-as.Date(scan(,''),'%j'),'%e')),`if`((a-1)%%10>2|a%/%10==1,'th',c("st","nd","rd")[a%%10]),f(d,' %B'))
Try it online!
$endgroup$
$begingroup$
How about tio.run/##HYxBCsIwEEWvIoEwMzDVRldi40K8hQgdmwQV20oSd949xm4e/… for 134 bytes
$endgroup$
– Nick Kennedy
4 hours ago
$begingroup$
Yes, I need to learn`if`
better. Thanks.
$endgroup$
– CT Hall
2 hours ago
add a comment |
$begingroup$
R, 158 134 bytes
-24 bytes @Nick Kennedy for golfing the 'st', 'nd', 'rd', & 'th'. Thanks!
f=format;paste0(a<-as.double(f(d<-as.Date(scan(,''),'%j'),'%e')),`if`((a-1)%%10>2|a%/%10==1,'th',c("st","nd","rd")[a%%10]),f(d,' %B'))
Try it online!
$endgroup$
R, 158 134 bytes
-24 bytes @Nick Kennedy for golfing the 'st', 'nd', 'rd', & 'th'. Thanks!
f=format;paste0(a<-as.double(f(d<-as.Date(scan(,''),'%j'),'%e')),`if`((a-1)%%10>2|a%/%10==1,'th',c("st","nd","rd")[a%%10]),f(d,' %B'))
Try it online!
edited 2 hours ago
answered 5 hours ago
CT HallCT Hall
3419
3419
$begingroup$
How about tio.run/##HYxBCsIwEEWvIoEwMzDVRldi40K8hQgdmwQV20oSd949xm4e/… for 134 bytes
$endgroup$
– Nick Kennedy
4 hours ago
$begingroup$
Yes, I need to learn`if`
better. Thanks.
$endgroup$
– CT Hall
2 hours ago
add a comment |
$begingroup$
How about tio.run/##HYxBCsIwEEWvIoEwMzDVRldi40K8hQgdmwQV20oSd949xm4e/… for 134 bytes
$endgroup$
– Nick Kennedy
4 hours ago
$begingroup$
Yes, I need to learn`if`
better. Thanks.
$endgroup$
– CT Hall
2 hours ago
$begingroup$
How about tio.run/##HYxBCsIwEEWvIoEwMzDVRldi40K8hQgdmwQV20oSd949xm4e/… for 134 bytes
$endgroup$
– Nick Kennedy
4 hours ago
$begingroup$
How about tio.run/##HYxBCsIwEEWvIoEwMzDVRldi40K8hQgdmwQV20oSd949xm4e/… for 134 bytes
$endgroup$
– Nick Kennedy
4 hours ago
$begingroup$
Yes, I need to learn
`if`
better. Thanks.$endgroup$
– CT Hall
2 hours ago
$begingroup$
Yes, I need to learn
`if`
better. Thanks.$endgroup$
– CT Hall
2 hours ago
add a comment |
$begingroup$
Perl 6, 166 163 bytes
{.day~(<th st nd rd>[.day%30%20]||'th')~' '~ <January February March April May June July August September October November December>[.month-1]}o*+Date.new(1,1,1)-1
Try it online!
When you hardcode the month names, but still beat the previous Perl 6 answer that didn't >.<
$endgroup$
add a comment |
$begingroup$
Perl 6, 166 163 bytes
{.day~(<th st nd rd>[.day%30%20]||'th')~' '~ <January February March April May June July August September October November December>[.month-1]}o*+Date.new(1,1,1)-1
Try it online!
When you hardcode the month names, but still beat the previous Perl 6 answer that didn't >.<
$endgroup$
add a comment |
$begingroup$
Perl 6, 166 163 bytes
{.day~(<th st nd rd>[.day%30%20]||'th')~' '~ <January February March April May June July August September October November December>[.month-1]}o*+Date.new(1,1,1)-1
Try it online!
When you hardcode the month names, but still beat the previous Perl 6 answer that didn't >.<
$endgroup$
Perl 6, 166 163 bytes
{.day~(<th st nd rd>[.day%30%20]||'th')~' '~ <January February March April May June July August September October November December>[.month-1]}o*+Date.new(1,1,1)-1
Try it online!
When you hardcode the month names, but still beat the previous Perl 6 answer that didn't >.<
edited 37 mins ago
answered 54 mins ago
Jo KingJo King
24.8k358128
24.8k358128
add a comment |
add a comment |
$begingroup$
Jelly, 115 114 bytes
’%⁵<3a:⁵n1Ɗ×%⁵$Ḥ+ؽị“thstndrd”ṭ
“5<Ḟ’b4+28ÄŻ_@µ>0T,>0$ƇZṪµ1ịị“1;8-UÞẆĊƬṁɱkzIṇkµ⁴ JḷJdɱ<©Q£Ƈ.dẊṘh!İḞẠƒĊ¶÷»Ỵ¤,2ịÇƊṚK
Try it online!
Long by Jelly standards, but done from first principles.
$endgroup$
add a comment |
$begingroup$
Jelly, 115 114 bytes
’%⁵<3a:⁵n1Ɗ×%⁵$Ḥ+ؽị“thstndrd”ṭ
“5<Ḟ’b4+28ÄŻ_@µ>0T,>0$ƇZṪµ1ịị“1;8-UÞẆĊƬṁɱkzIṇkµ⁴ JḷJdɱ<©Q£Ƈ.dẊṘh!İḞẠƒĊ¶÷»Ỵ¤,2ịÇƊṚK
Try it online!
Long by Jelly standards, but done from first principles.
$endgroup$
add a comment |
$begingroup$
Jelly, 115 114 bytes
’%⁵<3a:⁵n1Ɗ×%⁵$Ḥ+ؽị“thstndrd”ṭ
“5<Ḟ’b4+28ÄŻ_@µ>0T,>0$ƇZṪµ1ịị“1;8-UÞẆĊƬṁɱkzIṇkµ⁴ JḷJdɱ<©Q£Ƈ.dẊṘh!İḞẠƒĊ¶÷»Ỵ¤,2ịÇƊṚK
Try it online!
Long by Jelly standards, but done from first principles.
$endgroup$
Jelly, 115 114 bytes
’%⁵<3a:⁵n1Ɗ×%⁵$Ḥ+ؽị“thstndrd”ṭ
“5<Ḟ’b4+28ÄŻ_@µ>0T,>0$ƇZṪµ1ịị“1;8-UÞẆĊƬṁɱkzIṇkµ⁴ JḷJdɱ<©Q£Ƈ.dẊṘh!İḞẠƒĊ¶÷»Ỵ¤,2ịÇƊṚK
Try it online!
Long by Jelly standards, but done from first principles.
edited 25 mins ago
answered 1 hour ago
Nick KennedyNick Kennedy
66137
66137
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).
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%2f181468%2fits-a-yearly-task-alright%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
$begingroup$
What is "Day-number Month" format? I'm assuming it's "20th March"? Or is it "20 March"? That makes a pretty big difference, if you need ordinals.
$endgroup$
– Riker
7 hours ago
3
$begingroup$
Also, do you need to force an error message on numbers > 365? Can the program just assume that's invalid input and it won't need to handle that?
$endgroup$
– Riker
7 hours ago
4
$begingroup$
As not everyone is a native English speaker, you may want to add that day numbers 11, 12, and 13 get "th", numbers ending in "1" get "st", "2" get "nd", "3" get "rd", and all other get "th".
$endgroup$
– Adám
7 hours ago
4
$begingroup$
Whoa, don't accept answers so quickly. Especially not wrong answers!
$endgroup$
– Adám
6 hours ago
3
$begingroup$
You should add at least
11
(11th January) and21
(21st January) to the test cases.$endgroup$
– Arnauld
6 hours ago