It's a yearly task, alrightTips for golfing in 05AB1EConvert an Excel date code to a “date”Day of the...
What changes for testers when they are testing in agile environments?
What is going on with 'gets(stdin)' on the site coderbyte?
What does chmod -u do?
Added a new user on Ubuntu, set password not working?
How to write values with uncertainty and units with brackets: (339+-14) m/s
Rising and falling intonation
Redundant comparison & "if" before assignment
What does routing an IP address mean?
Are the IPv6 address space and IPv4 address space completely disjoint?
Strong empirical falsification of quantum mechanics based on vacuum energy density
Yosemite Fire Rings - What to Expect?
How do you make your own symbol when Detexify fails?
How create a shell/bash script for some Linux command?
Why should universal income be universal?
copy and scale one figure (wheel)
Non-trope happy ending?
Is (0,1] a closed or open set?
Multiplicative persistence
How should I respond when I lied about my education and the company finds out through background check?
What if a revenant (monster) gains fire resistance?
How can Trident be so inexpensive? Will it orbit Triton or just do a (slow) flyby?
Why Shazam when there is already Superman?
Count the occurrence of each unique word in the file
Is aluminum electrical wire used on aircraft?
It's a yearly task, alright
Tips for golfing in 05AB1EConvert an Excel date code to a “date”Day of the week of the next Feb 29thRollover CalendarRoman-style date formattingFriday the 13thThe Last MondaymonthconcatenationToday in the YOLDDate OccurrencesASCII Calendar PlannerConvert an Excel date code to a “date”
$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 9 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$
4
$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
Mar 13 at 15:29
5
$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
Mar 13 at 15:38
9
$begingroup$
Whoa, don't accept answers so quickly. Especially not wrong answers!
$endgroup$
– Adám
Mar 13 at 16:10
6
$begingroup$
You should add at least11
(11th January) and21
(21st January) to the test cases.
$endgroup$
– Arnauld
Mar 13 at 16:30
1
$begingroup$
And while you're editing test cases, maybe specify what exactly your test case format is. A couple of answerers have thought that123=
was part of the required output. Or simply edit your test cases to read something like:365
gives31st December
$endgroup$
– Adám
Mar 13 at 16:36
|
show 9 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 Mar 13 at 17:03
Andrew
asked Mar 13 at 15:24
AndrewAndrew
16019
16019
4
$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
Mar 13 at 15:29
5
$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
Mar 13 at 15:38
9
$begingroup$
Whoa, don't accept answers so quickly. Especially not wrong answers!
$endgroup$
– Adám
Mar 13 at 16:10
6
$begingroup$
You should add at least11
(11th January) and21
(21st January) to the test cases.
$endgroup$
– Arnauld
Mar 13 at 16:30
1
$begingroup$
And while you're editing test cases, maybe specify what exactly your test case format is. A couple of answerers have thought that123=
was part of the required output. Or simply edit your test cases to read something like:365
gives31st December
$endgroup$
– Adám
Mar 13 at 16:36
|
show 9 more comments
4
$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
Mar 13 at 15:29
5
$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
Mar 13 at 15:38
9
$begingroup$
Whoa, don't accept answers so quickly. Especially not wrong answers!
$endgroup$
– Adám
Mar 13 at 16:10
6
$begingroup$
You should add at least11
(11th January) and21
(21st January) to the test cases.
$endgroup$
– Arnauld
Mar 13 at 16:30
1
$begingroup$
And while you're editing test cases, maybe specify what exactly your test case format is. A couple of answerers have thought that123=
was part of the required output. Or simply edit your test cases to read something like:365
gives31st December
$endgroup$
– Adám
Mar 13 at 16:36
4
4
$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
Mar 13 at 15:29
$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
Mar 13 at 15:29
5
5
$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
Mar 13 at 15:38
$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
Mar 13 at 15:38
9
9
$begingroup$
Whoa, don't accept answers so quickly. Especially not wrong answers!
$endgroup$
– Adám
Mar 13 at 16:10
$begingroup$
Whoa, don't accept answers so quickly. Especially not wrong answers!
$endgroup$
– Adám
Mar 13 at 16:10
6
6
$begingroup$
You should add at least
11
(11th January) and 21
(21st January) to the test cases.$endgroup$
– Arnauld
Mar 13 at 16:30
$begingroup$
You should add at least
11
(11th January) and 21
(21st January) to the test cases.$endgroup$
– Arnauld
Mar 13 at 16:30
1
1
$begingroup$
And while you're editing test cases, maybe specify what exactly your test case format is. A couple of answerers have thought that
123=
was part of the required output. Or simply edit your test cases to read something like: 365
gives 31st December
$endgroup$
– Adám
Mar 13 at 16:36
$begingroup$
And while you're editing test cases, maybe specify what exactly your test case format is. A couple of answerers have thought that
123=
was part of the required output. Or simply edit your test cases to read something like: 365
gives 31st December
$endgroup$
– Adám
Mar 13 at 16:36
|
show 9 more comments
21 Answers
21
active
oldest
votes
$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
Mar 13 at 16:23
$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
Mar 13 at 16:31
add a comment |
$begingroup$
Jelly, 79 78 77 bytes
-1 fixing a bug :) (shouldn't pre-transpose to find index, should post-reverse, but then we can tail rather than head)
-1 using reflection (⁽©ṅB+30_2¦2
-> ⁽0ṗb4+28m0
)
⁽0ṗb4+28m0SRṁRƲœiµṪȮ%30%20«4ị“nḄƲf⁷»s3¤Ṗ,ị“£ṢtẒ⁽ẹ½MḊxɲȧėAṅ ɓaṾ¥D¹ṀẏD8÷ṬØ»Ḳ¤$K
A full program which prints the result
Try it online!
How?
will update this later...
⁽©ṅB+30_2¦2SRṁRƲZœiµḢȮ%30%20«4ị“nḄƲf⁷»s3¤Ṗ,ị“...»Ḳ¤$K - Main Link: integer, n
⁽©ṅB+30_2¦2SRṁRƲZœi - f(n) to get list of integers, [day, month]
⁽©ṅ - compressed literal 2741
B - to a list of binary digits -> [ 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1]
+30 - add thirty [31,30,31,30,31,30,31,31,30,31,30,31]
¦ - sparse application...
2 - ...to indices: [2]
_ 2 - ...action: subtract two [31,28,31,30,31,30,31,31,30,31,30,31]
Ʋ - last four links as a monad - i.e. f(x):
S - sum x 365
R - range [1..365]
R - range x (vectorises) [[1..31],[1..28],...]
ṁ - mould like [[1..31],[32..59],...]
Z - transpose [[1,32,...],[2,33,...],...]
œi - 1st multi-dimensional index of n -> [day, month]
µḢȮ%30%20«4ị“nḄƲf⁷»s3¤Ṗ,ị“...»Ḳ¤$K - given [day, month] format and print
µ - start a new monadic chain - i.e. f(x=[day, month])
Ḣ - head -- get the day leaving x as [month])
Ȯ - print it (with no newline) and yield it
%30 - modulo by thirty
%20 - modulo by twenty
«4 - minimum of that and four
¤ - nilad followed by link(s) as a nilad:
“nḄƲf⁷» - dictionary words "standard"+" the" = "standard the"
s3 - split into threes = ["sta","nda","rd ","the"]
ị - index into
Ṗ - remove rightmost character
¤ - nilad followed by link(s) as a nilad:
“...» - dictionary words "January"+" February"+...
Ḳ - split at spaces = ["January","February",...]
ị - index into (vectorises across [month])
, - pair e.g. ["th", ["February"]]
K - join with spaces ["th ", "February"]
- print (implicitly smashes) th February
$endgroup$
3
$begingroup$
The "standard the" trick is amazing.
$endgroup$
– Ven
Mar 15 at 9:17
$begingroup$
I agree with @Ven, great trick! It also saved a byte in my 05AB1E answer in comparison to the compressed string"thstndrd"
split into parts of size 2 (.•oθ2(w•2ô
), so thanks. :)
$endgroup$
– Kevin Cruijssen
Mar 15 at 11:03
$begingroup$
This has to be one of the longest Jelly programs I have ever seen.
$endgroup$
– JAD
Mar 15 at 12:41
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 115 113 bytes
n=>{var g=p.AddDays(n-1);int f=g.Day,m=f%30%20<4?f%10:0;return$"{f}{"tsnr"[m]}{"htdd"[m]} {g:MMMM}";};DateTime p;
Takes advantage of the fact DateTime is a struct.
Try it online!
$endgroup$
1
$begingroup$
@KevinCruijssen I got the modulos out of order, should be fixed now.
$endgroup$
– Embodiment of Ignorance
Mar 14 at 14:59
$begingroup$
.code.tio(2,22): error CS0165: Use of unassigned local variable 'p'
It appears that the struct thing doesn't work.
$endgroup$
– JAD
Mar 15 at 12:45
$begingroup$
var g=new DateTime().AddDays(n-1)
works though
$endgroup$
– JAD
Mar 15 at 12:50
$begingroup$
@JAD mistake on my part, fixed
$endgroup$
– Embodiment of Ignorance
Mar 15 at 15:00
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$
add a comment |
$begingroup$
Perl 6, 166 161 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!
Hardcodes all the month names, which takes up most of the space. Man, Perl 6 really needs a proper date formatter.
$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
Mar 13 at 16:17
$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
Mar 13 at 16:18
1
$begingroup$
@gwaugh Made mine Hack instead.
$endgroup$
– Ven
Mar 13 at 16:26
$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
Mar 13 at 16:42
add a comment |
$begingroup$
JavaScript (ES6), 117 113 bytes
Saved 4 bytes thanks to @tsh
d=>(n=(d=new Date(1,0,d)).getDate())+([,'st','nd','rd'][n%30%20]||'th')+' '+d.toLocaleString('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.toLocaleString( // 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
Mar 13 at 16:04
1
$begingroup$
@ExpiredData Thanks for reporting this. Fixed now.
$endgroup$
– Arnauld
Mar 13 at 16:16
$begingroup$
Ignore my comment, I made an ID10T error.
$endgroup$
– asgallant
Mar 13 at 21:10
$begingroup$
I'm not sure how nodejs handle language tags, but it seems using0
would work as using"en"
. And changing totoLocaleString
would save 4 bytes. 110 bytes
$endgroup$
– tsh
Mar 14 at 2:39
$begingroup$
@tsh It seems thattoLocaleString
is using the system default settings when it's passed an unrecognized string or a numeric value. So, it can be anything. This parameter is basically ineffective on a TIO instance, because only English locales are installed anyway.
$endgroup$
– Arnauld
Mar 14 at 8:17
add a comment |
$begingroup$
Smalltalk, 126 bytes
d:=Date year:1day:n.k:=m:=d dayOfMonth.10<k&(k<14)and:[k:=0].o:={#st.#nd.#rd}at:k\10ifAbsent:#th.m asString,o,' ',d monthName
$endgroup$
1
$begingroup$
I don't know Smalltalk, but is this correct for11th,12th,13th
? If I read correctly you integer-divide the day by 10, but that would mean it would result in11st,12nd,13rd
, unless something else in the code fixes this while I'm unaware of it.
$endgroup$
– Kevin Cruijssen
Mar 14 at 10:58
$begingroup$
@KevinCruijssen You are right. Thanks for calling my attention on this. I'll need to spend some more bytes to fix this.
$endgroup$
– Leandro Caniglia
Mar 14 at 16:19
1
$begingroup$
@KevinCruijssen, Done. Thanks again.
$endgroup$
– Leandro Caniglia
Mar 15 at 1:58
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!
$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
Mar 13 at 19:07
$begingroup$
116 bytes
$endgroup$
– Embodiment of Ignorance
Mar 13 at 20:02
$begingroup$
I'm pretty sure you have to add a semi-colon after theDataTime s
$endgroup$
– Embodiment of Ignorance
Mar 14 at 1:31
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$
1
$begingroup$
How about tio.run/##HYxBCsIwEEWvIoEwMzDVRldi40K8hQgdmwQV20oSd949xm4e/… for 134 bytes
$endgroup$
– Nick Kennedy
Mar 13 at 18:43
$begingroup$
Yes, I need to learn`if`
better. Thanks.
$endgroup$
– CT Hall
Mar 13 at 20:09
add a comment |
$begingroup$
MySQL, 47 45 42 bytes
SELECT DATE_FORMAT(MAKEDATE(1,n),"%D %M")
1901 can be replaced with any year that was/is not a leap year.
Edit: saved two bytes by removing spaces and another three bytes by changing the year to 1, thanks to @Embodyment of Ignorance.
$endgroup$
$begingroup$
Can you remove the spaces between1901, n
and the string?
$endgroup$
– Embodiment of Ignorance
Mar 14 at 15:31
$begingroup$
@EmbodimentofIgnorance yes I can, thanks!
$endgroup$
– NicolasB
Mar 14 at 15:32
$begingroup$
Also, why not replace 1901 with a year like 1? 1 isn't a leap year, and it's 3 bytes shorter
$endgroup$
– Embodiment of Ignorance
Mar 14 at 15:32
$begingroup$
@EmbodimentofIgnorance done and done :-)
$endgroup$
– NicolasB
Mar 14 at 15:35
add a comment |
$begingroup$
05AB1E, 81 79 78 76 75 74 73 71 70 bytes
•ΘÏF•ºS₂+.¥-D0›©ÏθD30%20%4‚ß„—ÊØ3ôsè¨ð”……‚應…ä†ï€¿…Ë…ê†Ä…æ…Ì…Í”#®OèJ
-8 bytes thanks to @Grimy.
-1 byte thanks to @JonathanAllan's standard the
trick for th,st,nd,rd
, which he used in his Jelly answer.
Try it online or verify all possible test cases.
Explanation:
•ΘÏF• # Push compressed integer 5254545
º # Mirror it vertically: 52545455454525
S # Converted to a list of digits: [5,2,5,4,5,4,5,5,4,5,4,5,2,5]
₂+ # And 26 to each: [31,28,31,30,31,30,31,31,30,31,30,31,28,31]
# (the additional trailing 28,31 won't cause any issues)
.¥ # Undelta this list (with automatic leading 0):
# [0,31,59,90,120,151,181,212,243,273,304,334,365,393,424]
- # Subtract each from the (implicit) input-integer
D0› # Duplicate the list, and check for each if it's positive (> 0)
© # Store the resulting list in the register (without popping)
Ï # Only leave the values at those truthy indices
θ # And get the last value from the list, which is our day
D # Duplicate this day
30%20% # Take modulo-30, followed by modulo-20
# (21,22,23,31 will result in 1,2,3,1; everything else stays the same)
4‚ # Pair it with 4
ß # Pop and push the minimum of the two (so the result is one of 0,1,2,3,4)
…thŠØ # Push dictionary string "th standards"
3ô # Split it into parts of size 3: ["th ","sta","nda","rds"]
sè # Swap and index the integer into this list (4 wraps around to index 0)
¨ # And remove the trailing character from this string
ð # Push a space " "
”……‚應…ä†ï€¿…Ë…ê†Ä…æ…Ì…Í”
# Push dictionary string "December January February March April May June July August September October November"
# # Split on spaces
® # Push the list of truthy/falsey values from the register again
O # Get the amount of truthy values by taking the sum
è # Use that to index into the string-list of months (12 wraps around to index 0)
J # Join everything on the stack together to a single string
# (and output the result implicitly)
See this 05AB1E tip of mine to understand why:
- (section How to use the dictionary?)
”……‚應…ä†ï€¿…Ë…ê†Ä…æ…Ì…Í”
is"December January February March April May June July August September October November"
- (section How to use the dictionary?)
…thŠØ
is"th standards"
- (section How to compress large integers?)
•ΘÏF•
is5254545
$endgroup$
1
$begingroup$
-2 bytes by using 5в28+ for compression: TIO
$endgroup$
– Grimy
Mar 14 at 14:35
$begingroup$
@Grimy Thanks! Too bad•!₆%ζ3•S
and•CoAc•5в
are the same amount of bytes. Almost thought I could save another byte by using a compressed integer instead of integer list. :)
$endgroup$
– Kevin Cruijssen
Mar 14 at 15:05
$begingroup$
Using S is a good idea, -1 byte again: TIO
$endgroup$
– Grimy
Mar 14 at 15:45
1
$begingroup$
-1 again (using "th standards" instead of "standard the" removes the need forÁ
).
$endgroup$
– Grimy
Mar 19 at 16:52
1
$begingroup$
-1 (•C.ñÒā•
to•ΘÏF•º
, the extra digits don't matter)
$endgroup$
– Grimy
Mar 20 at 12:51
|
show 6 more comments
$begingroup$
bash, 82 80 bytes
-2 bytes thanks to @ASCII-only
a=(th st nd rd);set `printf "%(%e %B)T" $[$1*86399]`;echo $1${a[$1%30%20]-th} $2
TIO
bash +GNU date, 77 bytes
a=(th st nd rd);set `date -d@$[$1*86399] +%e %B`;echo $1${a[$1%30%20]-th} $2
$endgroup$
$begingroup$
80?
$endgroup$
– ASCII-only
Mar 14 at 11:35
$begingroup$
@ASCII-only, yes subtracting 100s for each day, 100*365 = 36500s which is less than one day (86400), works also with 86399 (subtract 1s by day)
$endgroup$
– Nahuel Fouilleul
Mar 14 at 11:42
$begingroup$
:/ still looks really long but haven't found a better way yet
$endgroup$
– ASCII-only
Mar 14 at 11:52
add a comment |
$begingroup$
Shell + coreutils, 112 90 bytes
date -d0-12-31 $1day +%-dth %B|sed 's/1th/1st/;s/2th/2nd/;s/3th/3rd/;s/(1.).. /1th /'
Try it online! Link includes test cases. Edit: Saved 22 bytes thanks to @NahuelFouilleul. Explanation:
date -d0-12-31 $1day
Calculate the number of day(s) after the first day preceding a non-leap year. (Sadly you can't do relative date calculations from @-1
.)
+%-dth %B|sed
Output the day of month (without leading zero), th
, and the full month name.
's/1th/1st/;s/2th/2nd/;s/3th/3rd/;
Fix up 1st
, 2nd
, 3rd
, 21st
, 22nd
, 23rd
and 31st
.
s/(1.).. /1th /'
Restore 11th
to 13th
.
$endgroup$
$begingroup$
i saw this answer after mine, could save 18bytes using one sed command, alsos
indays
can be removed, and19
in1969
$endgroup$
– Nahuel Fouilleul
Mar 14 at 11:09
$begingroup$
@NahuelFouilleul That last one uses a Bash-ism so should be posted as a separate answer, but thanks for the other tips!
$endgroup$
– Neil
Mar 14 at 11:49
add a comment |
$begingroup$
Jelly, 115 114 101 97 bytes
%30%20¹0<?4Ḥ+ؽị“thstndrd”ṭ
“5<Ḟ’b4+28ÄŻ_@µ>0T,>0$ƇZṪµ1ịị“£ṢtẒ⁽ẹ½MḊxɲȧėAṅ ɓaṾ¥D¹ṀẏD8÷ṬØ»Ḳ¤,2ịÇƊṚK
Try it online!
Long by Jelly standards, but done from first principles.
Thanks to @JonathanAllan for saving 13 bytes through better understanding of string compression.
$endgroup$
$begingroup$
“£ṢtẒ⁽ẹ½MḊxɲȧėAṅ ɓaṾ¥D¹ṀẏD8÷ṬØ»Ḳ¤
would save 13 (Compress.dictionary looks for a leading space and has special handling for it).
$endgroup$
– Jonathan Allan
Mar 14 at 12:13
add a comment |
$begingroup$
Google Sheets, 118 103 86 bytes
=day(A1+1)&mid("stndrdth",min(7,1+2*mod(mod(day(A1+1)-1,30),20)),2)&text(A1+1," mmmm")
I can't edit my comment so, here's a working version of the Google Sheets code.
Try it Online!
$endgroup$
add a comment |
$begingroup$
Red, 124 bytes
func[n][d: 1-1-1 + n - 1[rejoin[d/4 either 5 > t: d/4 % 30 % 20[pick[th st nd rd]t + 1]['th]]pick system/locale/months d/3]]
Try it online!
Adds n
- 1 days to 1-1-1 (1-Jan-2001) to form a date, than uses Arnauld's method to index into month suffixes. Too bad Red is 1-indexed, this requires additional tweaking. The good thing is that Red knows the names of the months :)
$endgroup$
add a comment |
$begingroup$
APL(NARS), 235 chars, 470 bytes
{k←↑⍸0<w←+v←(1-⍵),(12⍴28)+13561787⊤⍨12⍴4⋄k<2:¯1⋄d←1+v[k]-w[k]⋄(⍕d),({d∊11..13:'th'⋄1=10∣d:'st'⋄2=10∣d:'nd'⋄3=10∣d:'rd'⋄'th'}),' ',(k-1)⊃(m≠' ')⊂m←'January February March April May June July August September October November December'}
13561787 is the number that in base 4 can be summed to (12⍴28) for obtain the lenght of each month...
test:
f←{k←↑⍸0<w←+v←(1-⍵),(12⍴28)+13561787⊤⍨12⍴4⋄k<2:¯1⋄d←1+v[k]-w[k]⋄(⍕d),({d∊11..13:'th'⋄1=10∣d:'st'⋄2=10∣d:'nd'⋄3=10∣d:'rd'⋄'th'}),' ',(k-1)⊃(m≠' ')⊂m←'January February March April May June July August September October November December'}
⊃f¨1 2 3 365 60 11
1st January
2nd January
3rd January
31st December
1st March
11th January
$endgroup$
add a comment |
$begingroup$
C (gcc), 174 155 bytes
i;char a[99],*b="thstndrd";f(long x){x--;x*=86400;strftime(a,98,"%d %B",gmtime(&x));i=*a==49?0:a[1]-48;a[2]=b[i=i>3?0:i*2];a[3]=b[++i];x=*a==48?a+1:a;}
Try it online!
$endgroup$
add a comment |
$begingroup$
TSQL, 83 bytes
DECLARE @ datetime=4
-1PRINT format(@,'d'+left(substring('stndrd',day(@)%20*3-2,3)+'th',3)+' MMMM')
Abusing substring returns empty string when the input is out of range. Also abusing an integer can be assigned to a datetime while subtracting 1 in the code.
Try it out
$endgroup$
add a comment |
$begingroup$
Python 3, 95 Bytes
Datetimed it :P
from datetime import *;f=lambda s:(datetime(2019,1,1)+timedelta(days=s-1)).strftime("%d of %B")
Try it online!
New contributor
$endgroup$
1
$begingroup$
This doesn't produce the ordinal suffixes, and has leading zeroes in the day number. Theof
is also unnecessary
$endgroup$
– Jo King
Mar 19 at 12:10
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
21 Answers
21
active
oldest
votes
21 Answers
21
active
oldest
votes
active
oldest
votes
active
oldest
votes
$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
Mar 13 at 16:23
$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
Mar 13 at 16:31
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
Mar 13 at 16:23
$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
Mar 13 at 16:31
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 Mar 13 at 18:53
answered Mar 13 at 16:15
gwaughgwaugh
1,948515
1,948515
$begingroup$
why's the-n
necessary?
$endgroup$
– Ven
Mar 13 at 16:23
$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
Mar 13 at 16:31
add a comment |
$begingroup$
why's the-n
necessary?
$endgroup$
– Ven
Mar 13 at 16:23
$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
Mar 13 at 16:31
$begingroup$
why's the
-n
necessary?$endgroup$
– Ven
Mar 13 at 16:23
$begingroup$
why's the
-n
necessary?$endgroup$
– Ven
Mar 13 at 16:23
$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
Mar 13 at 16:31
$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
Mar 13 at 16:31
add a comment |
$begingroup$
Jelly, 79 78 77 bytes
-1 fixing a bug :) (shouldn't pre-transpose to find index, should post-reverse, but then we can tail rather than head)
-1 using reflection (⁽©ṅB+30_2¦2
-> ⁽0ṗb4+28m0
)
⁽0ṗb4+28m0SRṁRƲœiµṪȮ%30%20«4ị“nḄƲf⁷»s3¤Ṗ,ị“£ṢtẒ⁽ẹ½MḊxɲȧėAṅ ɓaṾ¥D¹ṀẏD8÷ṬØ»Ḳ¤$K
A full program which prints the result
Try it online!
How?
will update this later...
⁽©ṅB+30_2¦2SRṁRƲZœiµḢȮ%30%20«4ị“nḄƲf⁷»s3¤Ṗ,ị“...»Ḳ¤$K - Main Link: integer, n
⁽©ṅB+30_2¦2SRṁRƲZœi - f(n) to get list of integers, [day, month]
⁽©ṅ - compressed literal 2741
B - to a list of binary digits -> [ 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1]
+30 - add thirty [31,30,31,30,31,30,31,31,30,31,30,31]
¦ - sparse application...
2 - ...to indices: [2]
_ 2 - ...action: subtract two [31,28,31,30,31,30,31,31,30,31,30,31]
Ʋ - last four links as a monad - i.e. f(x):
S - sum x 365
R - range [1..365]
R - range x (vectorises) [[1..31],[1..28],...]
ṁ - mould like [[1..31],[32..59],...]
Z - transpose [[1,32,...],[2,33,...],...]
œi - 1st multi-dimensional index of n -> [day, month]
µḢȮ%30%20«4ị“nḄƲf⁷»s3¤Ṗ,ị“...»Ḳ¤$K - given [day, month] format and print
µ - start a new monadic chain - i.e. f(x=[day, month])
Ḣ - head -- get the day leaving x as [month])
Ȯ - print it (with no newline) and yield it
%30 - modulo by thirty
%20 - modulo by twenty
«4 - minimum of that and four
¤ - nilad followed by link(s) as a nilad:
“nḄƲf⁷» - dictionary words "standard"+" the" = "standard the"
s3 - split into threes = ["sta","nda","rd ","the"]
ị - index into
Ṗ - remove rightmost character
¤ - nilad followed by link(s) as a nilad:
“...» - dictionary words "January"+" February"+...
Ḳ - split at spaces = ["January","February",...]
ị - index into (vectorises across [month])
, - pair e.g. ["th", ["February"]]
K - join with spaces ["th ", "February"]
- print (implicitly smashes) th February
$endgroup$
3
$begingroup$
The "standard the" trick is amazing.
$endgroup$
– Ven
Mar 15 at 9:17
$begingroup$
I agree with @Ven, great trick! It also saved a byte in my 05AB1E answer in comparison to the compressed string"thstndrd"
split into parts of size 2 (.•oθ2(w•2ô
), so thanks. :)
$endgroup$
– Kevin Cruijssen
Mar 15 at 11:03
$begingroup$
This has to be one of the longest Jelly programs I have ever seen.
$endgroup$
– JAD
Mar 15 at 12:41
add a comment |
$begingroup$
Jelly, 79 78 77 bytes
-1 fixing a bug :) (shouldn't pre-transpose to find index, should post-reverse, but then we can tail rather than head)
-1 using reflection (⁽©ṅB+30_2¦2
-> ⁽0ṗb4+28m0
)
⁽0ṗb4+28m0SRṁRƲœiµṪȮ%30%20«4ị“nḄƲf⁷»s3¤Ṗ,ị“£ṢtẒ⁽ẹ½MḊxɲȧėAṅ ɓaṾ¥D¹ṀẏD8÷ṬØ»Ḳ¤$K
A full program which prints the result
Try it online!
How?
will update this later...
⁽©ṅB+30_2¦2SRṁRƲZœiµḢȮ%30%20«4ị“nḄƲf⁷»s3¤Ṗ,ị“...»Ḳ¤$K - Main Link: integer, n
⁽©ṅB+30_2¦2SRṁRƲZœi - f(n) to get list of integers, [day, month]
⁽©ṅ - compressed literal 2741
B - to a list of binary digits -> [ 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1]
+30 - add thirty [31,30,31,30,31,30,31,31,30,31,30,31]
¦ - sparse application...
2 - ...to indices: [2]
_ 2 - ...action: subtract two [31,28,31,30,31,30,31,31,30,31,30,31]
Ʋ - last four links as a monad - i.e. f(x):
S - sum x 365
R - range [1..365]
R - range x (vectorises) [[1..31],[1..28],...]
ṁ - mould like [[1..31],[32..59],...]
Z - transpose [[1,32,...],[2,33,...],...]
œi - 1st multi-dimensional index of n -> [day, month]
µḢȮ%30%20«4ị“nḄƲf⁷»s3¤Ṗ,ị“...»Ḳ¤$K - given [day, month] format and print
µ - start a new monadic chain - i.e. f(x=[day, month])
Ḣ - head -- get the day leaving x as [month])
Ȯ - print it (with no newline) and yield it
%30 - modulo by thirty
%20 - modulo by twenty
«4 - minimum of that and four
¤ - nilad followed by link(s) as a nilad:
“nḄƲf⁷» - dictionary words "standard"+" the" = "standard the"
s3 - split into threes = ["sta","nda","rd ","the"]
ị - index into
Ṗ - remove rightmost character
¤ - nilad followed by link(s) as a nilad:
“...» - dictionary words "January"+" February"+...
Ḳ - split at spaces = ["January","February",...]
ị - index into (vectorises across [month])
, - pair e.g. ["th", ["February"]]
K - join with spaces ["th ", "February"]
- print (implicitly smashes) th February
$endgroup$
3
$begingroup$
The "standard the" trick is amazing.
$endgroup$
– Ven
Mar 15 at 9:17
$begingroup$
I agree with @Ven, great trick! It also saved a byte in my 05AB1E answer in comparison to the compressed string"thstndrd"
split into parts of size 2 (.•oθ2(w•2ô
), so thanks. :)
$endgroup$
– Kevin Cruijssen
Mar 15 at 11:03
$begingroup$
This has to be one of the longest Jelly programs I have ever seen.
$endgroup$
– JAD
Mar 15 at 12:41
add a comment |
$begingroup$
Jelly, 79 78 77 bytes
-1 fixing a bug :) (shouldn't pre-transpose to find index, should post-reverse, but then we can tail rather than head)
-1 using reflection (⁽©ṅB+30_2¦2
-> ⁽0ṗb4+28m0
)
⁽0ṗb4+28m0SRṁRƲœiµṪȮ%30%20«4ị“nḄƲf⁷»s3¤Ṗ,ị“£ṢtẒ⁽ẹ½MḊxɲȧėAṅ ɓaṾ¥D¹ṀẏD8÷ṬØ»Ḳ¤$K
A full program which prints the result
Try it online!
How?
will update this later...
⁽©ṅB+30_2¦2SRṁRƲZœiµḢȮ%30%20«4ị“nḄƲf⁷»s3¤Ṗ,ị“...»Ḳ¤$K - Main Link: integer, n
⁽©ṅB+30_2¦2SRṁRƲZœi - f(n) to get list of integers, [day, month]
⁽©ṅ - compressed literal 2741
B - to a list of binary digits -> [ 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1]
+30 - add thirty [31,30,31,30,31,30,31,31,30,31,30,31]
¦ - sparse application...
2 - ...to indices: [2]
_ 2 - ...action: subtract two [31,28,31,30,31,30,31,31,30,31,30,31]
Ʋ - last four links as a monad - i.e. f(x):
S - sum x 365
R - range [1..365]
R - range x (vectorises) [[1..31],[1..28],...]
ṁ - mould like [[1..31],[32..59],...]
Z - transpose [[1,32,...],[2,33,...],...]
œi - 1st multi-dimensional index of n -> [day, month]
µḢȮ%30%20«4ị“nḄƲf⁷»s3¤Ṗ,ị“...»Ḳ¤$K - given [day, month] format and print
µ - start a new monadic chain - i.e. f(x=[day, month])
Ḣ - head -- get the day leaving x as [month])
Ȯ - print it (with no newline) and yield it
%30 - modulo by thirty
%20 - modulo by twenty
«4 - minimum of that and four
¤ - nilad followed by link(s) as a nilad:
“nḄƲf⁷» - dictionary words "standard"+" the" = "standard the"
s3 - split into threes = ["sta","nda","rd ","the"]
ị - index into
Ṗ - remove rightmost character
¤ - nilad followed by link(s) as a nilad:
“...» - dictionary words "January"+" February"+...
Ḳ - split at spaces = ["January","February",...]
ị - index into (vectorises across [month])
, - pair e.g. ["th", ["February"]]
K - join with spaces ["th ", "February"]
- print (implicitly smashes) th February
$endgroup$
Jelly, 79 78 77 bytes
-1 fixing a bug :) (shouldn't pre-transpose to find index, should post-reverse, but then we can tail rather than head)
-1 using reflection (⁽©ṅB+30_2¦2
-> ⁽0ṗb4+28m0
)
⁽0ṗb4+28m0SRṁRƲœiµṪȮ%30%20«4ị“nḄƲf⁷»s3¤Ṗ,ị“£ṢtẒ⁽ẹ½MḊxɲȧėAṅ ɓaṾ¥D¹ṀẏD8÷ṬØ»Ḳ¤$K
A full program which prints the result
Try it online!
How?
will update this later...
⁽©ṅB+30_2¦2SRṁRƲZœiµḢȮ%30%20«4ị“nḄƲf⁷»s3¤Ṗ,ị“...»Ḳ¤$K - Main Link: integer, n
⁽©ṅB+30_2¦2SRṁRƲZœi - f(n) to get list of integers, [day, month]
⁽©ṅ - compressed literal 2741
B - to a list of binary digits -> [ 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1]
+30 - add thirty [31,30,31,30,31,30,31,31,30,31,30,31]
¦ - sparse application...
2 - ...to indices: [2]
_ 2 - ...action: subtract two [31,28,31,30,31,30,31,31,30,31,30,31]
Ʋ - last four links as a monad - i.e. f(x):
S - sum x 365
R - range [1..365]
R - range x (vectorises) [[1..31],[1..28],...]
ṁ - mould like [[1..31],[32..59],...]
Z - transpose [[1,32,...],[2,33,...],...]
œi - 1st multi-dimensional index of n -> [day, month]
µḢȮ%30%20«4ị“nḄƲf⁷»s3¤Ṗ,ị“...»Ḳ¤$K - given [day, month] format and print
µ - start a new monadic chain - i.e. f(x=[day, month])
Ḣ - head -- get the day leaving x as [month])
Ȯ - print it (with no newline) and yield it
%30 - modulo by thirty
%20 - modulo by twenty
«4 - minimum of that and four
¤ - nilad followed by link(s) as a nilad:
“nḄƲf⁷» - dictionary words "standard"+" the" = "standard the"
s3 - split into threes = ["sta","nda","rd ","the"]
ị - index into
Ṗ - remove rightmost character
¤ - nilad followed by link(s) as a nilad:
“...» - dictionary words "January"+" February"+...
Ḳ - split at spaces = ["January","February",...]
ị - index into (vectorises across [month])
, - pair e.g. ["th", ["February"]]
K - join with spaces ["th ", "February"]
- print (implicitly smashes) th February
edited Mar 15 at 11:53
answered Mar 14 at 16:43
Jonathan AllanJonathan Allan
53.4k535172
53.4k535172
3
$begingroup$
The "standard the" trick is amazing.
$endgroup$
– Ven
Mar 15 at 9:17
$begingroup$
I agree with @Ven, great trick! It also saved a byte in my 05AB1E answer in comparison to the compressed string"thstndrd"
split into parts of size 2 (.•oθ2(w•2ô
), so thanks. :)
$endgroup$
– Kevin Cruijssen
Mar 15 at 11:03
$begingroup$
This has to be one of the longest Jelly programs I have ever seen.
$endgroup$
– JAD
Mar 15 at 12:41
add a comment |
3
$begingroup$
The "standard the" trick is amazing.
$endgroup$
– Ven
Mar 15 at 9:17
$begingroup$
I agree with @Ven, great trick! It also saved a byte in my 05AB1E answer in comparison to the compressed string"thstndrd"
split into parts of size 2 (.•oθ2(w•2ô
), so thanks. :)
$endgroup$
– Kevin Cruijssen
Mar 15 at 11:03
$begingroup$
This has to be one of the longest Jelly programs I have ever seen.
$endgroup$
– JAD
Mar 15 at 12:41
3
3
$begingroup$
The "standard the" trick is amazing.
$endgroup$
– Ven
Mar 15 at 9:17
$begingroup$
The "standard the" trick is amazing.
$endgroup$
– Ven
Mar 15 at 9:17
$begingroup$
I agree with @Ven, great trick! It also saved a byte in my 05AB1E answer in comparison to the compressed string
"thstndrd"
split into parts of size 2 (.•oθ2(w•2ô
), so thanks. :)$endgroup$
– Kevin Cruijssen
Mar 15 at 11:03
$begingroup$
I agree with @Ven, great trick! It also saved a byte in my 05AB1E answer in comparison to the compressed string
"thstndrd"
split into parts of size 2 (.•oθ2(w•2ô
), so thanks. :)$endgroup$
– Kevin Cruijssen
Mar 15 at 11:03
$begingroup$
This has to be one of the longest Jelly programs I have ever seen.
$endgroup$
– JAD
Mar 15 at 12:41
$begingroup$
This has to be one of the longest Jelly programs I have ever seen.
$endgroup$
– JAD
Mar 15 at 12:41
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 115 113 bytes
n=>{var g=p.AddDays(n-1);int f=g.Day,m=f%30%20<4?f%10:0;return$"{f}{"tsnr"[m]}{"htdd"[m]} {g:MMMM}";};DateTime p;
Takes advantage of the fact DateTime is a struct.
Try it online!
$endgroup$
1
$begingroup$
@KevinCruijssen I got the modulos out of order, should be fixed now.
$endgroup$
– Embodiment of Ignorance
Mar 14 at 14:59
$begingroup$
.code.tio(2,22): error CS0165: Use of unassigned local variable 'p'
It appears that the struct thing doesn't work.
$endgroup$
– JAD
Mar 15 at 12:45
$begingroup$
var g=new DateTime().AddDays(n-1)
works though
$endgroup$
– JAD
Mar 15 at 12:50
$begingroup$
@JAD mistake on my part, fixed
$endgroup$
– Embodiment of Ignorance
Mar 15 at 15:00
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 115 113 bytes
n=>{var g=p.AddDays(n-1);int f=g.Day,m=f%30%20<4?f%10:0;return$"{f}{"tsnr"[m]}{"htdd"[m]} {g:MMMM}";};DateTime p;
Takes advantage of the fact DateTime is a struct.
Try it online!
$endgroup$
1
$begingroup$
@KevinCruijssen I got the modulos out of order, should be fixed now.
$endgroup$
– Embodiment of Ignorance
Mar 14 at 14:59
$begingroup$
.code.tio(2,22): error CS0165: Use of unassigned local variable 'p'
It appears that the struct thing doesn't work.
$endgroup$
– JAD
Mar 15 at 12:45
$begingroup$
var g=new DateTime().AddDays(n-1)
works though
$endgroup$
– JAD
Mar 15 at 12:50
$begingroup$
@JAD mistake on my part, fixed
$endgroup$
– Embodiment of Ignorance
Mar 15 at 15:00
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 115 113 bytes
n=>{var g=p.AddDays(n-1);int f=g.Day,m=f%30%20<4?f%10:0;return$"{f}{"tsnr"[m]}{"htdd"[m]} {g:MMMM}";};DateTime p;
Takes advantage of the fact DateTime is a struct.
Try it online!
$endgroup$
C# (Visual C# Interactive Compiler), 115 113 bytes
n=>{var g=p.AddDays(n-1);int f=g.Day,m=f%30%20<4?f%10:0;return$"{f}{"tsnr"[m]}{"htdd"[m]} {g:MMMM}";};DateTime p;
Takes advantage of the fact DateTime is a struct.
Try it online!
edited Mar 15 at 15:01
answered Mar 13 at 19:58
Embodiment of IgnoranceEmbodiment of Ignorance
2,138125
2,138125
1
$begingroup$
@KevinCruijssen I got the modulos out of order, should be fixed now.
$endgroup$
– Embodiment of Ignorance
Mar 14 at 14:59
$begingroup$
.code.tio(2,22): error CS0165: Use of unassigned local variable 'p'
It appears that the struct thing doesn't work.
$endgroup$
– JAD
Mar 15 at 12:45
$begingroup$
var g=new DateTime().AddDays(n-1)
works though
$endgroup$
– JAD
Mar 15 at 12:50
$begingroup$
@JAD mistake on my part, fixed
$endgroup$
– Embodiment of Ignorance
Mar 15 at 15:00
add a comment |
1
$begingroup$
@KevinCruijssen I got the modulos out of order, should be fixed now.
$endgroup$
– Embodiment of Ignorance
Mar 14 at 14:59
$begingroup$
.code.tio(2,22): error CS0165: Use of unassigned local variable 'p'
It appears that the struct thing doesn't work.
$endgroup$
– JAD
Mar 15 at 12:45
$begingroup$
var g=new DateTime().AddDays(n-1)
works though
$endgroup$
– JAD
Mar 15 at 12:50
$begingroup$
@JAD mistake on my part, fixed
$endgroup$
– Embodiment of Ignorance
Mar 15 at 15:00
1
1
$begingroup$
@KevinCruijssen I got the modulos out of order, should be fixed now.
$endgroup$
– Embodiment of Ignorance
Mar 14 at 14:59
$begingroup$
@KevinCruijssen I got the modulos out of order, should be fixed now.
$endgroup$
– Embodiment of Ignorance
Mar 14 at 14:59
$begingroup$
.code.tio(2,22): error CS0165: Use of unassigned local variable 'p'
It appears that the struct thing doesn't work.$endgroup$
– JAD
Mar 15 at 12:45
$begingroup$
.code.tio(2,22): error CS0165: Use of unassigned local variable 'p'
It appears that the struct thing doesn't work.$endgroup$
– JAD
Mar 15 at 12:45
$begingroup$
var g=new DateTime().AddDays(n-1)
works though$endgroup$
– JAD
Mar 15 at 12:50
$begingroup$
var g=new DateTime().AddDays(n-1)
works though$endgroup$
– JAD
Mar 15 at 12:50
$begingroup$
@JAD mistake on my part, fixed
$endgroup$
– Embodiment of Ignorance
Mar 15 at 15:00
$begingroup$
@JAD mistake on my part, fixed
$endgroup$
– Embodiment of Ignorance
Mar 15 at 15:00
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$
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$
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 Mar 13 at 22:28
answered Mar 13 at 20:51
Erik the OutgolferErik the Outgolfer
32.7k429105
32.7k429105
add a comment |
add a comment |
$begingroup$
Perl 6, 166 161 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!
Hardcodes all the month names, which takes up most of the space. Man, Perl 6 really needs a proper date formatter.
$endgroup$
add a comment |
$begingroup$
Perl 6, 166 161 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!
Hardcodes all the month names, which takes up most of the space. Man, Perl 6 really needs a proper date formatter.
$endgroup$
add a comment |
$begingroup$
Perl 6, 166 161 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!
Hardcodes all the month names, which takes up most of the space. Man, Perl 6 really needs a proper date formatter.
$endgroup$
Perl 6, 166 161 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!
Hardcodes all the month names, which takes up most of the space. Man, Perl 6 really needs a proper date formatter.
edited Mar 14 at 0:45
answered Mar 13 at 22:01
Jo KingJo King
25.2k360129
25.2k360129
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
Mar 13 at 16:17
$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
Mar 13 at 16:18
1
$begingroup$
@gwaugh Made mine Hack instead.
$endgroup$
– Ven
Mar 13 at 16:26
$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
Mar 13 at 16:42
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
Mar 13 at 16:17
$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
Mar 13 at 16:18
1
$begingroup$
@gwaugh Made mine Hack instead.
$endgroup$
– Ven
Mar 13 at 16:26
$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
Mar 13 at 16:42
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 Mar 13 at 16:44
answered Mar 13 at 16:08
VenVen
2,43511223
2,43511223
$begingroup$
Wow, great minds think alike. :) +1 to you sir!
$endgroup$
– gwaugh
Mar 13 at 16:17
$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
Mar 13 at 16:18
1
$begingroup$
@gwaugh Made mine Hack instead.
$endgroup$
– Ven
Mar 13 at 16:26
$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
Mar 13 at 16:42
add a comment |
$begingroup$
Wow, great minds think alike. :) +1 to you sir!
$endgroup$
– gwaugh
Mar 13 at 16:17
$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
Mar 13 at 16:18
1
$begingroup$
@gwaugh Made mine Hack instead.
$endgroup$
– Ven
Mar 13 at 16:26
$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
Mar 13 at 16:42
$begingroup$
Wow, great minds think alike. :) +1 to you sir!
$endgroup$
– gwaugh
Mar 13 at 16:17
$begingroup$
Wow, great minds think alike. :) +1 to you sir!
$endgroup$
– gwaugh
Mar 13 at 16:17
$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
Mar 13 at 16:18
$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
Mar 13 at 16:18
1
1
$begingroup$
@gwaugh Made mine Hack instead.
$endgroup$
– Ven
Mar 13 at 16:26
$begingroup$
@gwaugh Made mine Hack instead.
$endgroup$
– Ven
Mar 13 at 16:26
$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
Mar 13 at 16:42
$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
Mar 13 at 16:42
add a comment |
$begingroup$
JavaScript (ES6), 117 113 bytes
Saved 4 bytes thanks to @tsh
d=>(n=(d=new Date(1,0,d)).getDate())+([,'st','nd','rd'][n%30%20]||'th')+' '+d.toLocaleString('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.toLocaleString( // 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
Mar 13 at 16:04
1
$begingroup$
@ExpiredData Thanks for reporting this. Fixed now.
$endgroup$
– Arnauld
Mar 13 at 16:16
$begingroup$
Ignore my comment, I made an ID10T error.
$endgroup$
– asgallant
Mar 13 at 21:10
$begingroup$
I'm not sure how nodejs handle language tags, but it seems using0
would work as using"en"
. And changing totoLocaleString
would save 4 bytes. 110 bytes
$endgroup$
– tsh
Mar 14 at 2:39
$begingroup$
@tsh It seems thattoLocaleString
is using the system default settings when it's passed an unrecognized string or a numeric value. So, it can be anything. This parameter is basically ineffective on a TIO instance, because only English locales are installed anyway.
$endgroup$
– Arnauld
Mar 14 at 8:17
add a comment |
$begingroup$
JavaScript (ES6), 117 113 bytes
Saved 4 bytes thanks to @tsh
d=>(n=(d=new Date(1,0,d)).getDate())+([,'st','nd','rd'][n%30%20]||'th')+' '+d.toLocaleString('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.toLocaleString( // 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
Mar 13 at 16:04
1
$begingroup$
@ExpiredData Thanks for reporting this. Fixed now.
$endgroup$
– Arnauld
Mar 13 at 16:16
$begingroup$
Ignore my comment, I made an ID10T error.
$endgroup$
– asgallant
Mar 13 at 21:10
$begingroup$
I'm not sure how nodejs handle language tags, but it seems using0
would work as using"en"
. And changing totoLocaleString
would save 4 bytes. 110 bytes
$endgroup$
– tsh
Mar 14 at 2:39
$begingroup$
@tsh It seems thattoLocaleString
is using the system default settings when it's passed an unrecognized string or a numeric value. So, it can be anything. This parameter is basically ineffective on a TIO instance, because only English locales are installed anyway.
$endgroup$
– Arnauld
Mar 14 at 8:17
add a comment |
$begingroup$
JavaScript (ES6), 117 113 bytes
Saved 4 bytes thanks to @tsh
d=>(n=(d=new Date(1,0,d)).getDate())+([,'st','nd','rd'][n%30%20]||'th')+' '+d.toLocaleString('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.toLocaleString( // 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 113 bytes
Saved 4 bytes thanks to @tsh
d=>(n=(d=new Date(1,0,d)).getDate())+([,'st','nd','rd'][n%30%20]||'th')+' '+d.toLocaleString('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.toLocaleString( // 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 Mar 14 at 8:07
answered Mar 13 at 16:01
ArnauldArnauld
79.5k796330
79.5k796330
$begingroup$
Fails for 11th,12th,13th of each month
$endgroup$
– Expired Data
Mar 13 at 16:04
1
$begingroup$
@ExpiredData Thanks for reporting this. Fixed now.
$endgroup$
– Arnauld
Mar 13 at 16:16
$begingroup$
Ignore my comment, I made an ID10T error.
$endgroup$
– asgallant
Mar 13 at 21:10
$begingroup$
I'm not sure how nodejs handle language tags, but it seems using0
would work as using"en"
. And changing totoLocaleString
would save 4 bytes. 110 bytes
$endgroup$
– tsh
Mar 14 at 2:39
$begingroup$
@tsh It seems thattoLocaleString
is using the system default settings when it's passed an unrecognized string or a numeric value. So, it can be anything. This parameter is basically ineffective on a TIO instance, because only English locales are installed anyway.
$endgroup$
– Arnauld
Mar 14 at 8:17
add a comment |
$begingroup$
Fails for 11th,12th,13th of each month
$endgroup$
– Expired Data
Mar 13 at 16:04
1
$begingroup$
@ExpiredData Thanks for reporting this. Fixed now.
$endgroup$
– Arnauld
Mar 13 at 16:16
$begingroup$
Ignore my comment, I made an ID10T error.
$endgroup$
– asgallant
Mar 13 at 21:10
$begingroup$
I'm not sure how nodejs handle language tags, but it seems using0
would work as using"en"
. And changing totoLocaleString
would save 4 bytes. 110 bytes
$endgroup$
– tsh
Mar 14 at 2:39
$begingroup$
@tsh It seems thattoLocaleString
is using the system default settings when it's passed an unrecognized string or a numeric value. So, it can be anything. This parameter is basically ineffective on a TIO instance, because only English locales are installed anyway.
$endgroup$
– Arnauld
Mar 14 at 8:17
$begingroup$
Fails for 11th,12th,13th of each month
$endgroup$
– Expired Data
Mar 13 at 16:04
$begingroup$
Fails for 11th,12th,13th of each month
$endgroup$
– Expired Data
Mar 13 at 16:04
1
1
$begingroup$
@ExpiredData Thanks for reporting this. Fixed now.
$endgroup$
– Arnauld
Mar 13 at 16:16
$begingroup$
@ExpiredData Thanks for reporting this. Fixed now.
$endgroup$
– Arnauld
Mar 13 at 16:16
$begingroup$
Ignore my comment, I made an ID10T error.
$endgroup$
– asgallant
Mar 13 at 21:10
$begingroup$
Ignore my comment, I made an ID10T error.
$endgroup$
– asgallant
Mar 13 at 21:10
$begingroup$
I'm not sure how nodejs handle language tags, but it seems using
0
would work as using "en"
. And changing to toLocaleString
would save 4 bytes. 110 bytes$endgroup$
– tsh
Mar 14 at 2:39
$begingroup$
I'm not sure how nodejs handle language tags, but it seems using
0
would work as using "en"
. And changing to toLocaleString
would save 4 bytes. 110 bytes$endgroup$
– tsh
Mar 14 at 2:39
$begingroup$
@tsh It seems that
toLocaleString
is using the system default settings when it's passed an unrecognized string or a numeric value. So, it can be anything. This parameter is basically ineffective on a TIO instance, because only English locales are installed anyway.$endgroup$
– Arnauld
Mar 14 at 8:17
$begingroup$
@tsh It seems that
toLocaleString
is using the system default settings when it's passed an unrecognized string or a numeric value. So, it can be anything. This parameter is basically ineffective on a TIO instance, because only English locales are installed anyway.$endgroup$
– Arnauld
Mar 14 at 8:17
add a comment |
$begingroup$
Smalltalk, 126 bytes
d:=Date year:1day:n.k:=m:=d dayOfMonth.10<k&(k<14)and:[k:=0].o:={#st.#nd.#rd}at:k\10ifAbsent:#th.m asString,o,' ',d monthName
$endgroup$
1
$begingroup$
I don't know Smalltalk, but is this correct for11th,12th,13th
? If I read correctly you integer-divide the day by 10, but that would mean it would result in11st,12nd,13rd
, unless something else in the code fixes this while I'm unaware of it.
$endgroup$
– Kevin Cruijssen
Mar 14 at 10:58
$begingroup$
@KevinCruijssen You are right. Thanks for calling my attention on this. I'll need to spend some more bytes to fix this.
$endgroup$
– Leandro Caniglia
Mar 14 at 16:19
1
$begingroup$
@KevinCruijssen, Done. Thanks again.
$endgroup$
– Leandro Caniglia
Mar 15 at 1:58
add a comment |
$begingroup$
Smalltalk, 126 bytes
d:=Date year:1day:n.k:=m:=d dayOfMonth.10<k&(k<14)and:[k:=0].o:={#st.#nd.#rd}at:k\10ifAbsent:#th.m asString,o,' ',d monthName
$endgroup$
1
$begingroup$
I don't know Smalltalk, but is this correct for11th,12th,13th
? If I read correctly you integer-divide the day by 10, but that would mean it would result in11st,12nd,13rd
, unless something else in the code fixes this while I'm unaware of it.
$endgroup$
– Kevin Cruijssen
Mar 14 at 10:58
$begingroup$
@KevinCruijssen You are right. Thanks for calling my attention on this. I'll need to spend some more bytes to fix this.
$endgroup$
– Leandro Caniglia
Mar 14 at 16:19
1
$begingroup$
@KevinCruijssen, Done. Thanks again.
$endgroup$
– Leandro Caniglia
Mar 15 at 1:58
add a comment |
$begingroup$
Smalltalk, 126 bytes
d:=Date year:1day:n.k:=m:=d dayOfMonth.10<k&(k<14)and:[k:=0].o:={#st.#nd.#rd}at:k\10ifAbsent:#th.m asString,o,' ',d monthName
$endgroup$
Smalltalk, 126 bytes
d:=Date year:1day:n.k:=m:=d dayOfMonth.10<k&(k<14)and:[k:=0].o:={#st.#nd.#rd}at:k\10ifAbsent:#th.m asString,o,' ',d monthName
edited Mar 15 at 1:57
answered Mar 14 at 2:05
Leandro CanigliaLeandro Caniglia
1713
1713
1
$begingroup$
I don't know Smalltalk, but is this correct for11th,12th,13th
? If I read correctly you integer-divide the day by 10, but that would mean it would result in11st,12nd,13rd
, unless something else in the code fixes this while I'm unaware of it.
$endgroup$
– Kevin Cruijssen
Mar 14 at 10:58
$begingroup$
@KevinCruijssen You are right. Thanks for calling my attention on this. I'll need to spend some more bytes to fix this.
$endgroup$
– Leandro Caniglia
Mar 14 at 16:19
1
$begingroup$
@KevinCruijssen, Done. Thanks again.
$endgroup$
– Leandro Caniglia
Mar 15 at 1:58
add a comment |
1
$begingroup$
I don't know Smalltalk, but is this correct for11th,12th,13th
? If I read correctly you integer-divide the day by 10, but that would mean it would result in11st,12nd,13rd
, unless something else in the code fixes this while I'm unaware of it.
$endgroup$
– Kevin Cruijssen
Mar 14 at 10:58
$begingroup$
@KevinCruijssen You are right. Thanks for calling my attention on this. I'll need to spend some more bytes to fix this.
$endgroup$
– Leandro Caniglia
Mar 14 at 16:19
1
$begingroup$
@KevinCruijssen, Done. Thanks again.
$endgroup$
– Leandro Caniglia
Mar 15 at 1:58
1
1
$begingroup$
I don't know Smalltalk, but is this correct for
11th,12th,13th
? If I read correctly you integer-divide the day by 10, but that would mean it would result in 11st,12nd,13rd
, unless something else in the code fixes this while I'm unaware of it.$endgroup$
– Kevin Cruijssen
Mar 14 at 10:58
$begingroup$
I don't know Smalltalk, but is this correct for
11th,12th,13th
? If I read correctly you integer-divide the day by 10, but that would mean it would result in 11st,12nd,13rd
, unless something else in the code fixes this while I'm unaware of it.$endgroup$
– Kevin Cruijssen
Mar 14 at 10:58
$begingroup$
@KevinCruijssen You are right. Thanks for calling my attention on this. I'll need to spend some more bytes to fix this.
$endgroup$
– Leandro Caniglia
Mar 14 at 16:19
$begingroup$
@KevinCruijssen You are right. Thanks for calling my attention on this. I'll need to spend some more bytes to fix this.
$endgroup$
– Leandro Caniglia
Mar 14 at 16:19
1
1
$begingroup$
@KevinCruijssen, Done. Thanks again.
$endgroup$
– Leandro Caniglia
Mar 15 at 1:58
$begingroup$
@KevinCruijssen, Done. Thanks again.
$endgroup$
– Leandro Caniglia
Mar 15 at 1:58
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!
$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
Mar 13 at 19:07
$begingroup$
116 bytes
$endgroup$
– Embodiment of Ignorance
Mar 13 at 20:02
$begingroup$
I'm pretty sure you have to add a semi-colon after theDataTime s
$endgroup$
– Embodiment of Ignorance
Mar 14 at 1:31
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!
$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
Mar 13 at 19:07
$begingroup$
116 bytes
$endgroup$
– Embodiment of Ignorance
Mar 13 at 20:02
$begingroup$
I'm pretty sure you have to add a semi-colon after theDataTime s
$endgroup$
– Embodiment of Ignorance
Mar 14 at 1:31
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!
$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!
edited Mar 13 at 17:11
answered Mar 13 at 15:58
Expired DataExpired Data
2665
2665
$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
Mar 13 at 19:07
$begingroup$
116 bytes
$endgroup$
– Embodiment of Ignorance
Mar 13 at 20:02
$begingroup$
I'm pretty sure you have to add a semi-colon after theDataTime s
$endgroup$
– Embodiment of Ignorance
Mar 14 at 1:31
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
Mar 13 at 19:07
$begingroup$
116 bytes
$endgroup$
– Embodiment of Ignorance
Mar 13 at 20:02
$begingroup$
I'm pretty sure you have to add a semi-colon after theDataTime s
$endgroup$
– Embodiment of Ignorance
Mar 14 at 1:31
$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
Mar 13 at 19:07
$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
Mar 13 at 19:07
$begingroup$
116 bytes
$endgroup$
– Embodiment of Ignorance
Mar 13 at 20:02
$begingroup$
116 bytes
$endgroup$
– Embodiment of Ignorance
Mar 13 at 20:02
$begingroup$
I'm pretty sure you have to add a semi-colon after the
DataTime s
$endgroup$
– Embodiment of Ignorance
Mar 14 at 1:31
$begingroup$
I'm pretty sure you have to add a semi-colon after the
DataTime s
$endgroup$
– Embodiment of Ignorance
Mar 14 at 1:31
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$
1
$begingroup$
How about tio.run/##HYxBCsIwEEWvIoEwMzDVRldi40K8hQgdmwQV20oSd949xm4e/… for 134 bytes
$endgroup$
– Nick Kennedy
Mar 13 at 18:43
$begingroup$
Yes, I need to learn`if`
better. Thanks.
$endgroup$
– CT Hall
Mar 13 at 20:09
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$
1
$begingroup$
How about tio.run/##HYxBCsIwEEWvIoEwMzDVRldi40K8hQgdmwQV20oSd949xm4e/… for 134 bytes
$endgroup$
– Nick Kennedy
Mar 13 at 18:43
$begingroup$
Yes, I need to learn`if`
better. Thanks.
$endgroup$
– CT Hall
Mar 13 at 20:09
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 Mar 13 at 20:12
answered Mar 13 at 17:01
CT HallCT Hall
46110
46110
1
$begingroup$
How about tio.run/##HYxBCsIwEEWvIoEwMzDVRldi40K8hQgdmwQV20oSd949xm4e/… for 134 bytes
$endgroup$
– Nick Kennedy
Mar 13 at 18:43
$begingroup$
Yes, I need to learn`if`
better. Thanks.
$endgroup$
– CT Hall
Mar 13 at 20:09
add a comment |
1
$begingroup$
How about tio.run/##HYxBCsIwEEWvIoEwMzDVRldi40K8hQgdmwQV20oSd949xm4e/… for 134 bytes
$endgroup$
– Nick Kennedy
Mar 13 at 18:43
$begingroup$
Yes, I need to learn`if`
better. Thanks.
$endgroup$
– CT Hall
Mar 13 at 20:09
1
1
$begingroup$
How about tio.run/##HYxBCsIwEEWvIoEwMzDVRldi40K8hQgdmwQV20oSd949xm4e/… for 134 bytes
$endgroup$
– Nick Kennedy
Mar 13 at 18:43
$begingroup$
How about tio.run/##HYxBCsIwEEWvIoEwMzDVRldi40K8hQgdmwQV20oSd949xm4e/… for 134 bytes
$endgroup$
– Nick Kennedy
Mar 13 at 18:43
$begingroup$
Yes, I need to learn
`if`
better. Thanks.$endgroup$
– CT Hall
Mar 13 at 20:09
$begingroup$
Yes, I need to learn
`if`
better. Thanks.$endgroup$
– CT Hall
Mar 13 at 20:09
add a comment |
$begingroup$
MySQL, 47 45 42 bytes
SELECT DATE_FORMAT(MAKEDATE(1,n),"%D %M")
1901 can be replaced with any year that was/is not a leap year.
Edit: saved two bytes by removing spaces and another three bytes by changing the year to 1, thanks to @Embodyment of Ignorance.
$endgroup$
$begingroup$
Can you remove the spaces between1901, n
and the string?
$endgroup$
– Embodiment of Ignorance
Mar 14 at 15:31
$begingroup$
@EmbodimentofIgnorance yes I can, thanks!
$endgroup$
– NicolasB
Mar 14 at 15:32
$begingroup$
Also, why not replace 1901 with a year like 1? 1 isn't a leap year, and it's 3 bytes shorter
$endgroup$
– Embodiment of Ignorance
Mar 14 at 15:32
$begingroup$
@EmbodimentofIgnorance done and done :-)
$endgroup$
– NicolasB
Mar 14 at 15:35
add a comment |
$begingroup$
MySQL, 47 45 42 bytes
SELECT DATE_FORMAT(MAKEDATE(1,n),"%D %M")
1901 can be replaced with any year that was/is not a leap year.
Edit: saved two bytes by removing spaces and another three bytes by changing the year to 1, thanks to @Embodyment of Ignorance.
$endgroup$
$begingroup$
Can you remove the spaces between1901, n
and the string?
$endgroup$
– Embodiment of Ignorance
Mar 14 at 15:31
$begingroup$
@EmbodimentofIgnorance yes I can, thanks!
$endgroup$
– NicolasB
Mar 14 at 15:32
$begingroup$
Also, why not replace 1901 with a year like 1? 1 isn't a leap year, and it's 3 bytes shorter
$endgroup$
– Embodiment of Ignorance
Mar 14 at 15:32
$begingroup$
@EmbodimentofIgnorance done and done :-)
$endgroup$
– NicolasB
Mar 14 at 15:35
add a comment |
$begingroup$
MySQL, 47 45 42 bytes
SELECT DATE_FORMAT(MAKEDATE(1,n),"%D %M")
1901 can be replaced with any year that was/is not a leap year.
Edit: saved two bytes by removing spaces and another three bytes by changing the year to 1, thanks to @Embodyment of Ignorance.
$endgroup$
MySQL, 47 45 42 bytes
SELECT DATE_FORMAT(MAKEDATE(1,n),"%D %M")
1901 can be replaced with any year that was/is not a leap year.
Edit: saved two bytes by removing spaces and another three bytes by changing the year to 1, thanks to @Embodyment of Ignorance.
edited Mar 14 at 15:33
answered Mar 14 at 15:27
NicolasBNicolasB
1314
1314
$begingroup$
Can you remove the spaces between1901, n
and the string?
$endgroup$
– Embodiment of Ignorance
Mar 14 at 15:31
$begingroup$
@EmbodimentofIgnorance yes I can, thanks!
$endgroup$
– NicolasB
Mar 14 at 15:32
$begingroup$
Also, why not replace 1901 with a year like 1? 1 isn't a leap year, and it's 3 bytes shorter
$endgroup$
– Embodiment of Ignorance
Mar 14 at 15:32
$begingroup$
@EmbodimentofIgnorance done and done :-)
$endgroup$
– NicolasB
Mar 14 at 15:35
add a comment |
$begingroup$
Can you remove the spaces between1901, n
and the string?
$endgroup$
– Embodiment of Ignorance
Mar 14 at 15:31
$begingroup$
@EmbodimentofIgnorance yes I can, thanks!
$endgroup$
– NicolasB
Mar 14 at 15:32
$begingroup$
Also, why not replace 1901 with a year like 1? 1 isn't a leap year, and it's 3 bytes shorter
$endgroup$
– Embodiment of Ignorance
Mar 14 at 15:32
$begingroup$
@EmbodimentofIgnorance done and done :-)
$endgroup$
– NicolasB
Mar 14 at 15:35
$begingroup$
Can you remove the spaces between
1901, n
and the string?$endgroup$
– Embodiment of Ignorance
Mar 14 at 15:31
$begingroup$
Can you remove the spaces between
1901, n
and the string?$endgroup$
– Embodiment of Ignorance
Mar 14 at 15:31
$begingroup$
@EmbodimentofIgnorance yes I can, thanks!
$endgroup$
– NicolasB
Mar 14 at 15:32
$begingroup$
@EmbodimentofIgnorance yes I can, thanks!
$endgroup$
– NicolasB
Mar 14 at 15:32
$begingroup$
Also, why not replace 1901 with a year like 1? 1 isn't a leap year, and it's 3 bytes shorter
$endgroup$
– Embodiment of Ignorance
Mar 14 at 15:32
$begingroup$
Also, why not replace 1901 with a year like 1? 1 isn't a leap year, and it's 3 bytes shorter
$endgroup$
– Embodiment of Ignorance
Mar 14 at 15:32
$begingroup$
@EmbodimentofIgnorance done and done :-)
$endgroup$
– NicolasB
Mar 14 at 15:35
$begingroup$
@EmbodimentofIgnorance done and done :-)
$endgroup$
– NicolasB
Mar 14 at 15:35
add a comment |
$begingroup$
05AB1E, 81 79 78 76 75 74 73 71 70 bytes
•ΘÏF•ºS₂+.¥-D0›©ÏθD30%20%4‚ß„—ÊØ3ôsè¨ð”……‚應…ä†ï€¿…Ë…ê†Ä…æ…Ì…Í”#®OèJ
-8 bytes thanks to @Grimy.
-1 byte thanks to @JonathanAllan's standard the
trick for th,st,nd,rd
, which he used in his Jelly answer.
Try it online or verify all possible test cases.
Explanation:
•ΘÏF• # Push compressed integer 5254545
º # Mirror it vertically: 52545455454525
S # Converted to a list of digits: [5,2,5,4,5,4,5,5,4,5,4,5,2,5]
₂+ # And 26 to each: [31,28,31,30,31,30,31,31,30,31,30,31,28,31]
# (the additional trailing 28,31 won't cause any issues)
.¥ # Undelta this list (with automatic leading 0):
# [0,31,59,90,120,151,181,212,243,273,304,334,365,393,424]
- # Subtract each from the (implicit) input-integer
D0› # Duplicate the list, and check for each if it's positive (> 0)
© # Store the resulting list in the register (without popping)
Ï # Only leave the values at those truthy indices
θ # And get the last value from the list, which is our day
D # Duplicate this day
30%20% # Take modulo-30, followed by modulo-20
# (21,22,23,31 will result in 1,2,3,1; everything else stays the same)
4‚ # Pair it with 4
ß # Pop and push the minimum of the two (so the result is one of 0,1,2,3,4)
…thŠØ # Push dictionary string "th standards"
3ô # Split it into parts of size 3: ["th ","sta","nda","rds"]
sè # Swap and index the integer into this list (4 wraps around to index 0)
¨ # And remove the trailing character from this string
ð # Push a space " "
”……‚應…ä†ï€¿…Ë…ê†Ä…æ…Ì…Í”
# Push dictionary string "December January February March April May June July August September October November"
# # Split on spaces
® # Push the list of truthy/falsey values from the register again
O # Get the amount of truthy values by taking the sum
è # Use that to index into the string-list of months (12 wraps around to index 0)
J # Join everything on the stack together to a single string
# (and output the result implicitly)
See this 05AB1E tip of mine to understand why:
- (section How to use the dictionary?)
”……‚應…ä†ï€¿…Ë…ê†Ä…æ…Ì…Í”
is"December January February March April May June July August September October November"
- (section How to use the dictionary?)
…thŠØ
is"th standards"
- (section How to compress large integers?)
•ΘÏF•
is5254545
$endgroup$
1
$begingroup$
-2 bytes by using 5в28+ for compression: TIO
$endgroup$
– Grimy
Mar 14 at 14:35
$begingroup$
@Grimy Thanks! Too bad•!₆%ζ3•S
and•CoAc•5в
are the same amount of bytes. Almost thought I could save another byte by using a compressed integer instead of integer list. :)
$endgroup$
– Kevin Cruijssen
Mar 14 at 15:05
$begingroup$
Using S is a good idea, -1 byte again: TIO
$endgroup$
– Grimy
Mar 14 at 15:45
1
$begingroup$
-1 again (using "th standards" instead of "standard the" removes the need forÁ
).
$endgroup$
– Grimy
Mar 19 at 16:52
1
$begingroup$
-1 (•C.ñÒā•
to•ΘÏF•º
, the extra digits don't matter)
$endgroup$
– Grimy
Mar 20 at 12:51
|
show 6 more comments
$begingroup$
05AB1E, 81 79 78 76 75 74 73 71 70 bytes
•ΘÏF•ºS₂+.¥-D0›©ÏθD30%20%4‚ß„—ÊØ3ôsè¨ð”……‚應…ä†ï€¿…Ë…ê†Ä…æ…Ì…Í”#®OèJ
-8 bytes thanks to @Grimy.
-1 byte thanks to @JonathanAllan's standard the
trick for th,st,nd,rd
, which he used in his Jelly answer.
Try it online or verify all possible test cases.
Explanation:
•ΘÏF• # Push compressed integer 5254545
º # Mirror it vertically: 52545455454525
S # Converted to a list of digits: [5,2,5,4,5,4,5,5,4,5,4,5,2,5]
₂+ # And 26 to each: [31,28,31,30,31,30,31,31,30,31,30,31,28,31]
# (the additional trailing 28,31 won't cause any issues)
.¥ # Undelta this list (with automatic leading 0):
# [0,31,59,90,120,151,181,212,243,273,304,334,365,393,424]
- # Subtract each from the (implicit) input-integer
D0› # Duplicate the list, and check for each if it's positive (> 0)
© # Store the resulting list in the register (without popping)
Ï # Only leave the values at those truthy indices
θ # And get the last value from the list, which is our day
D # Duplicate this day
30%20% # Take modulo-30, followed by modulo-20
# (21,22,23,31 will result in 1,2,3,1; everything else stays the same)
4‚ # Pair it with 4
ß # Pop and push the minimum of the two (so the result is one of 0,1,2,3,4)
…thŠØ # Push dictionary string "th standards"
3ô # Split it into parts of size 3: ["th ","sta","nda","rds"]
sè # Swap and index the integer into this list (4 wraps around to index 0)
¨ # And remove the trailing character from this string
ð # Push a space " "
”……‚應…ä†ï€¿…Ë…ê†Ä…æ…Ì…Í”
# Push dictionary string "December January February March April May June July August September October November"
# # Split on spaces
® # Push the list of truthy/falsey values from the register again
O # Get the amount of truthy values by taking the sum
è # Use that to index into the string-list of months (12 wraps around to index 0)
J # Join everything on the stack together to a single string
# (and output the result implicitly)
See this 05AB1E tip of mine to understand why:
- (section How to use the dictionary?)
”……‚應…ä†ï€¿…Ë…ê†Ä…æ…Ì…Í”
is"December January February March April May June July August September October November"
- (section How to use the dictionary?)
…thŠØ
is"th standards"
- (section How to compress large integers?)
•ΘÏF•
is5254545
$endgroup$
1
$begingroup$
-2 bytes by using 5в28+ for compression: TIO
$endgroup$
– Grimy
Mar 14 at 14:35
$begingroup$
@Grimy Thanks! Too bad•!₆%ζ3•S
and•CoAc•5в
are the same amount of bytes. Almost thought I could save another byte by using a compressed integer instead of integer list. :)
$endgroup$
– Kevin Cruijssen
Mar 14 at 15:05
$begingroup$
Using S is a good idea, -1 byte again: TIO
$endgroup$
– Grimy
Mar 14 at 15:45
1
$begingroup$
-1 again (using "th standards" instead of "standard the" removes the need forÁ
).
$endgroup$
– Grimy
Mar 19 at 16:52
1
$begingroup$
-1 (•C.ñÒā•
to•ΘÏF•º
, the extra digits don't matter)
$endgroup$
– Grimy
Mar 20 at 12:51
|
show 6 more comments
$begingroup$
05AB1E, 81 79 78 76 75 74 73 71 70 bytes
•ΘÏF•ºS₂+.¥-D0›©ÏθD30%20%4‚ß„—ÊØ3ôsè¨ð”……‚應…ä†ï€¿…Ë…ê†Ä…æ…Ì…Í”#®OèJ
-8 bytes thanks to @Grimy.
-1 byte thanks to @JonathanAllan's standard the
trick for th,st,nd,rd
, which he used in his Jelly answer.
Try it online or verify all possible test cases.
Explanation:
•ΘÏF• # Push compressed integer 5254545
º # Mirror it vertically: 52545455454525
S # Converted to a list of digits: [5,2,5,4,5,4,5,5,4,5,4,5,2,5]
₂+ # And 26 to each: [31,28,31,30,31,30,31,31,30,31,30,31,28,31]
# (the additional trailing 28,31 won't cause any issues)
.¥ # Undelta this list (with automatic leading 0):
# [0,31,59,90,120,151,181,212,243,273,304,334,365,393,424]
- # Subtract each from the (implicit) input-integer
D0› # Duplicate the list, and check for each if it's positive (> 0)
© # Store the resulting list in the register (without popping)
Ï # Only leave the values at those truthy indices
θ # And get the last value from the list, which is our day
D # Duplicate this day
30%20% # Take modulo-30, followed by modulo-20
# (21,22,23,31 will result in 1,2,3,1; everything else stays the same)
4‚ # Pair it with 4
ß # Pop and push the minimum of the two (so the result is one of 0,1,2,3,4)
…thŠØ # Push dictionary string "th standards"
3ô # Split it into parts of size 3: ["th ","sta","nda","rds"]
sè # Swap and index the integer into this list (4 wraps around to index 0)
¨ # And remove the trailing character from this string
ð # Push a space " "
”……‚應…ä†ï€¿…Ë…ê†Ä…æ…Ì…Í”
# Push dictionary string "December January February March April May June July August September October November"
# # Split on spaces
® # Push the list of truthy/falsey values from the register again
O # Get the amount of truthy values by taking the sum
è # Use that to index into the string-list of months (12 wraps around to index 0)
J # Join everything on the stack together to a single string
# (and output the result implicitly)
See this 05AB1E tip of mine to understand why:
- (section How to use the dictionary?)
”……‚應…ä†ï€¿…Ë…ê†Ä…æ…Ì…Í”
is"December January February March April May June July August September October November"
- (section How to use the dictionary?)
…thŠØ
is"th standards"
- (section How to compress large integers?)
•ΘÏF•
is5254545
$endgroup$
05AB1E, 81 79 78 76 75 74 73 71 70 bytes
•ΘÏF•ºS₂+.¥-D0›©ÏθD30%20%4‚ß„—ÊØ3ôsè¨ð”……‚應…ä†ï€¿…Ë…ê†Ä…æ…Ì…Í”#®OèJ
-8 bytes thanks to @Grimy.
-1 byte thanks to @JonathanAllan's standard the
trick for th,st,nd,rd
, which he used in his Jelly answer.
Try it online or verify all possible test cases.
Explanation:
•ΘÏF• # Push compressed integer 5254545
º # Mirror it vertically: 52545455454525
S # Converted to a list of digits: [5,2,5,4,5,4,5,5,4,5,4,5,2,5]
₂+ # And 26 to each: [31,28,31,30,31,30,31,31,30,31,30,31,28,31]
# (the additional trailing 28,31 won't cause any issues)
.¥ # Undelta this list (with automatic leading 0):
# [0,31,59,90,120,151,181,212,243,273,304,334,365,393,424]
- # Subtract each from the (implicit) input-integer
D0› # Duplicate the list, and check for each if it's positive (> 0)
© # Store the resulting list in the register (without popping)
Ï # Only leave the values at those truthy indices
θ # And get the last value from the list, which is our day
D # Duplicate this day
30%20% # Take modulo-30, followed by modulo-20
# (21,22,23,31 will result in 1,2,3,1; everything else stays the same)
4‚ # Pair it with 4
ß # Pop and push the minimum of the two (so the result is one of 0,1,2,3,4)
…thŠØ # Push dictionary string "th standards"
3ô # Split it into parts of size 3: ["th ","sta","nda","rds"]
sè # Swap and index the integer into this list (4 wraps around to index 0)
¨ # And remove the trailing character from this string
ð # Push a space " "
”……‚應…ä†ï€¿…Ë…ê†Ä…æ…Ì…Í”
# Push dictionary string "December January February March April May June July August September October November"
# # Split on spaces
® # Push the list of truthy/falsey values from the register again
O # Get the amount of truthy values by taking the sum
è # Use that to index into the string-list of months (12 wraps around to index 0)
J # Join everything on the stack together to a single string
# (and output the result implicitly)
See this 05AB1E tip of mine to understand why:
- (section How to use the dictionary?)
”……‚應…ä†ï€¿…Ë…ê†Ä…æ…Ì…Í”
is"December January February March April May June July August September October November"
- (section How to use the dictionary?)
…thŠØ
is"th standards"
- (section How to compress large integers?)
•ΘÏF•
is5254545
edited Mar 20 at 13:05
answered Mar 14 at 10:50
Kevin CruijssenKevin Cruijssen
41.3k567213
41.3k567213
1
$begingroup$
-2 bytes by using 5в28+ for compression: TIO
$endgroup$
– Grimy
Mar 14 at 14:35
$begingroup$
@Grimy Thanks! Too bad•!₆%ζ3•S
and•CoAc•5в
are the same amount of bytes. Almost thought I could save another byte by using a compressed integer instead of integer list. :)
$endgroup$
– Kevin Cruijssen
Mar 14 at 15:05
$begingroup$
Using S is a good idea, -1 byte again: TIO
$endgroup$
– Grimy
Mar 14 at 15:45
1
$begingroup$
-1 again (using "th standards" instead of "standard the" removes the need forÁ
).
$endgroup$
– Grimy
Mar 19 at 16:52
1
$begingroup$
-1 (•C.ñÒā•
to•ΘÏF•º
, the extra digits don't matter)
$endgroup$
– Grimy
Mar 20 at 12:51
|
show 6 more comments
1
$begingroup$
-2 bytes by using 5в28+ for compression: TIO
$endgroup$
– Grimy
Mar 14 at 14:35
$begingroup$
@Grimy Thanks! Too bad•!₆%ζ3•S
and•CoAc•5в
are the same amount of bytes. Almost thought I could save another byte by using a compressed integer instead of integer list. :)
$endgroup$
– Kevin Cruijssen
Mar 14 at 15:05
$begingroup$
Using S is a good idea, -1 byte again: TIO
$endgroup$
– Grimy
Mar 14 at 15:45
1
$begingroup$
-1 again (using "th standards" instead of "standard the" removes the need forÁ
).
$endgroup$
– Grimy
Mar 19 at 16:52
1
$begingroup$
-1 (•C.ñÒā•
to•ΘÏF•º
, the extra digits don't matter)
$endgroup$
– Grimy
Mar 20 at 12:51
1
1
$begingroup$
-2 bytes by using 5в28+ for compression: TIO
$endgroup$
– Grimy
Mar 14 at 14:35
$begingroup$
-2 bytes by using 5в28+ for compression: TIO
$endgroup$
– Grimy
Mar 14 at 14:35
$begingroup$
@Grimy Thanks! Too bad
•!₆%ζ3•S
and •CoAc•5в
are the same amount of bytes. Almost thought I could save another byte by using a compressed integer instead of integer list. :)$endgroup$
– Kevin Cruijssen
Mar 14 at 15:05
$begingroup$
@Grimy Thanks! Too bad
•!₆%ζ3•S
and •CoAc•5в
are the same amount of bytes. Almost thought I could save another byte by using a compressed integer instead of integer list. :)$endgroup$
– Kevin Cruijssen
Mar 14 at 15:05
$begingroup$
Using S is a good idea, -1 byte again: TIO
$endgroup$
– Grimy
Mar 14 at 15:45
$begingroup$
Using S is a good idea, -1 byte again: TIO
$endgroup$
– Grimy
Mar 14 at 15:45
1
1
$begingroup$
-1 again (using "th standards" instead of "standard the" removes the need for
Á
).$endgroup$
– Grimy
Mar 19 at 16:52
$begingroup$
-1 again (using "th standards" instead of "standard the" removes the need for
Á
).$endgroup$
– Grimy
Mar 19 at 16:52
1
1
$begingroup$
-1 (
•C.ñÒā•
to •ΘÏF•º
, the extra digits don't matter)$endgroup$
– Grimy
Mar 20 at 12:51
$begingroup$
-1 (
•C.ñÒā•
to •ΘÏF•º
, the extra digits don't matter)$endgroup$
– Grimy
Mar 20 at 12:51
|
show 6 more comments
$begingroup$
bash, 82 80 bytes
-2 bytes thanks to @ASCII-only
a=(th st nd rd);set `printf "%(%e %B)T" $[$1*86399]`;echo $1${a[$1%30%20]-th} $2
TIO
bash +GNU date, 77 bytes
a=(th st nd rd);set `date -d@$[$1*86399] +%e %B`;echo $1${a[$1%30%20]-th} $2
$endgroup$
$begingroup$
80?
$endgroup$
– ASCII-only
Mar 14 at 11:35
$begingroup$
@ASCII-only, yes subtracting 100s for each day, 100*365 = 36500s which is less than one day (86400), works also with 86399 (subtract 1s by day)
$endgroup$
– Nahuel Fouilleul
Mar 14 at 11:42
$begingroup$
:/ still looks really long but haven't found a better way yet
$endgroup$
– ASCII-only
Mar 14 at 11:52
add a comment |
$begingroup$
bash, 82 80 bytes
-2 bytes thanks to @ASCII-only
a=(th st nd rd);set `printf "%(%e %B)T" $[$1*86399]`;echo $1${a[$1%30%20]-th} $2
TIO
bash +GNU date, 77 bytes
a=(th st nd rd);set `date -d@$[$1*86399] +%e %B`;echo $1${a[$1%30%20]-th} $2
$endgroup$
$begingroup$
80?
$endgroup$
– ASCII-only
Mar 14 at 11:35
$begingroup$
@ASCII-only, yes subtracting 100s for each day, 100*365 = 36500s which is less than one day (86400), works also with 86399 (subtract 1s by day)
$endgroup$
– Nahuel Fouilleul
Mar 14 at 11:42
$begingroup$
:/ still looks really long but haven't found a better way yet
$endgroup$
– ASCII-only
Mar 14 at 11:52
add a comment |
$begingroup$
bash, 82 80 bytes
-2 bytes thanks to @ASCII-only
a=(th st nd rd);set `printf "%(%e %B)T" $[$1*86399]`;echo $1${a[$1%30%20]-th} $2
TIO
bash +GNU date, 77 bytes
a=(th st nd rd);set `date -d@$[$1*86399] +%e %B`;echo $1${a[$1%30%20]-th} $2
$endgroup$
bash, 82 80 bytes
-2 bytes thanks to @ASCII-only
a=(th st nd rd);set `printf "%(%e %B)T" $[$1*86399]`;echo $1${a[$1%30%20]-th} $2
TIO
bash +GNU date, 77 bytes
a=(th st nd rd);set `date -d@$[$1*86399] +%e %B`;echo $1${a[$1%30%20]-th} $2
edited Mar 14 at 11:43
answered Mar 14 at 9:28
Nahuel FouilleulNahuel Fouilleul
2,905211
2,905211
$begingroup$
80?
$endgroup$
– ASCII-only
Mar 14 at 11:35
$begingroup$
@ASCII-only, yes subtracting 100s for each day, 100*365 = 36500s which is less than one day (86400), works also with 86399 (subtract 1s by day)
$endgroup$
– Nahuel Fouilleul
Mar 14 at 11:42
$begingroup$
:/ still looks really long but haven't found a better way yet
$endgroup$
– ASCII-only
Mar 14 at 11:52
add a comment |
$begingroup$
80?
$endgroup$
– ASCII-only
Mar 14 at 11:35
$begingroup$
@ASCII-only, yes subtracting 100s for each day, 100*365 = 36500s which is less than one day (86400), works also with 86399 (subtract 1s by day)
$endgroup$
– Nahuel Fouilleul
Mar 14 at 11:42
$begingroup$
:/ still looks really long but haven't found a better way yet
$endgroup$
– ASCII-only
Mar 14 at 11:52
$begingroup$
80?
$endgroup$
– ASCII-only
Mar 14 at 11:35
$begingroup$
80?
$endgroup$
– ASCII-only
Mar 14 at 11:35
$begingroup$
@ASCII-only, yes subtracting 100s for each day, 100*365 = 36500s which is less than one day (86400), works also with 86399 (subtract 1s by day)
$endgroup$
– Nahuel Fouilleul
Mar 14 at 11:42
$begingroup$
@ASCII-only, yes subtracting 100s for each day, 100*365 = 36500s which is less than one day (86400), works also with 86399 (subtract 1s by day)
$endgroup$
– Nahuel Fouilleul
Mar 14 at 11:42
$begingroup$
:/ still looks really long but haven't found a better way yet
$endgroup$
– ASCII-only
Mar 14 at 11:52
$begingroup$
:/ still looks really long but haven't found a better way yet
$endgroup$
– ASCII-only
Mar 14 at 11:52
add a comment |
$begingroup$
Shell + coreutils, 112 90 bytes
date -d0-12-31 $1day +%-dth %B|sed 's/1th/1st/;s/2th/2nd/;s/3th/3rd/;s/(1.).. /1th /'
Try it online! Link includes test cases. Edit: Saved 22 bytes thanks to @NahuelFouilleul. Explanation:
date -d0-12-31 $1day
Calculate the number of day(s) after the first day preceding a non-leap year. (Sadly you can't do relative date calculations from @-1
.)
+%-dth %B|sed
Output the day of month (without leading zero), th
, and the full month name.
's/1th/1st/;s/2th/2nd/;s/3th/3rd/;
Fix up 1st
, 2nd
, 3rd
, 21st
, 22nd
, 23rd
and 31st
.
s/(1.).. /1th /'
Restore 11th
to 13th
.
$endgroup$
$begingroup$
i saw this answer after mine, could save 18bytes using one sed command, alsos
indays
can be removed, and19
in1969
$endgroup$
– Nahuel Fouilleul
Mar 14 at 11:09
$begingroup$
@NahuelFouilleul That last one uses a Bash-ism so should be posted as a separate answer, but thanks for the other tips!
$endgroup$
– Neil
Mar 14 at 11:49
add a comment |
$begingroup$
Shell + coreutils, 112 90 bytes
date -d0-12-31 $1day +%-dth %B|sed 's/1th/1st/;s/2th/2nd/;s/3th/3rd/;s/(1.).. /1th /'
Try it online! Link includes test cases. Edit: Saved 22 bytes thanks to @NahuelFouilleul. Explanation:
date -d0-12-31 $1day
Calculate the number of day(s) after the first day preceding a non-leap year. (Sadly you can't do relative date calculations from @-1
.)
+%-dth %B|sed
Output the day of month (without leading zero), th
, and the full month name.
's/1th/1st/;s/2th/2nd/;s/3th/3rd/;
Fix up 1st
, 2nd
, 3rd
, 21st
, 22nd
, 23rd
and 31st
.
s/(1.).. /1th /'
Restore 11th
to 13th
.
$endgroup$
$begingroup$
i saw this answer after mine, could save 18bytes using one sed command, alsos
indays
can be removed, and19
in1969
$endgroup$
– Nahuel Fouilleul
Mar 14 at 11:09
$begingroup$
@NahuelFouilleul That last one uses a Bash-ism so should be posted as a separate answer, but thanks for the other tips!
$endgroup$
– Neil
Mar 14 at 11:49
add a comment |
$begingroup$
Shell + coreutils, 112 90 bytes
date -d0-12-31 $1day +%-dth %B|sed 's/1th/1st/;s/2th/2nd/;s/3th/3rd/;s/(1.).. /1th /'
Try it online! Link includes test cases. Edit: Saved 22 bytes thanks to @NahuelFouilleul. Explanation:
date -d0-12-31 $1day
Calculate the number of day(s) after the first day preceding a non-leap year. (Sadly you can't do relative date calculations from @-1
.)
+%-dth %B|sed
Output the day of month (without leading zero), th
, and the full month name.
's/1th/1st/;s/2th/2nd/;s/3th/3rd/;
Fix up 1st
, 2nd
, 3rd
, 21st
, 22nd
, 23rd
and 31st
.
s/(1.).. /1th /'
Restore 11th
to 13th
.
$endgroup$
Shell + coreutils, 112 90 bytes
date -d0-12-31 $1day +%-dth %B|sed 's/1th/1st/;s/2th/2nd/;s/3th/3rd/;s/(1.).. /1th /'
Try it online! Link includes test cases. Edit: Saved 22 bytes thanks to @NahuelFouilleul. Explanation:
date -d0-12-31 $1day
Calculate the number of day(s) after the first day preceding a non-leap year. (Sadly you can't do relative date calculations from @-1
.)
+%-dth %B|sed
Output the day of month (without leading zero), th
, and the full month name.
's/1th/1st/;s/2th/2nd/;s/3th/3rd/;
Fix up 1st
, 2nd
, 3rd
, 21st
, 22nd
, 23rd
and 31st
.
s/(1.).. /1th /'
Restore 11th
to 13th
.
edited Mar 14 at 11:48
answered Mar 13 at 23:45
NeilNeil
82k745178
82k745178
$begingroup$
i saw this answer after mine, could save 18bytes using one sed command, alsos
indays
can be removed, and19
in1969
$endgroup$
– Nahuel Fouilleul
Mar 14 at 11:09
$begingroup$
@NahuelFouilleul That last one uses a Bash-ism so should be posted as a separate answer, but thanks for the other tips!
$endgroup$
– Neil
Mar 14 at 11:49
add a comment |
$begingroup$
i saw this answer after mine, could save 18bytes using one sed command, alsos
indays
can be removed, and19
in1969
$endgroup$
– Nahuel Fouilleul
Mar 14 at 11:09
$begingroup$
@NahuelFouilleul That last one uses a Bash-ism so should be posted as a separate answer, but thanks for the other tips!
$endgroup$
– Neil
Mar 14 at 11:49
$begingroup$
i saw this answer after mine, could save 18bytes using one sed command, also
s
in days
can be removed, and 19
in 1969
$endgroup$
– Nahuel Fouilleul
Mar 14 at 11:09
$begingroup$
i saw this answer after mine, could save 18bytes using one sed command, also
s
in days
can be removed, and 19
in 1969
$endgroup$
– Nahuel Fouilleul
Mar 14 at 11:09
$begingroup$
@NahuelFouilleul That last one uses a Bash-ism so should be posted as a separate answer, but thanks for the other tips!
$endgroup$
– Neil
Mar 14 at 11:49
$begingroup$
@NahuelFouilleul That last one uses a Bash-ism so should be posted as a separate answer, but thanks for the other tips!
$endgroup$
– Neil
Mar 14 at 11:49
add a comment |
$begingroup$
Jelly, 115 114 101 97 bytes
%30%20¹0<?4Ḥ+ؽị“thstndrd”ṭ
“5<Ḟ’b4+28ÄŻ_@µ>0T,>0$ƇZṪµ1ịị“£ṢtẒ⁽ẹ½MḊxɲȧėAṅ ɓaṾ¥D¹ṀẏD8÷ṬØ»Ḳ¤,2ịÇƊṚK
Try it online!
Long by Jelly standards, but done from first principles.
Thanks to @JonathanAllan for saving 13 bytes through better understanding of string compression.
$endgroup$
$begingroup$
“£ṢtẒ⁽ẹ½MḊxɲȧėAṅ ɓaṾ¥D¹ṀẏD8÷ṬØ»Ḳ¤
would save 13 (Compress.dictionary looks for a leading space and has special handling for it).
$endgroup$
– Jonathan Allan
Mar 14 at 12:13
add a comment |
$begingroup$
Jelly, 115 114 101 97 bytes
%30%20¹0<?4Ḥ+ؽị“thstndrd”ṭ
“5<Ḟ’b4+28ÄŻ_@µ>0T,>0$ƇZṪµ1ịị“£ṢtẒ⁽ẹ½MḊxɲȧėAṅ ɓaṾ¥D¹ṀẏD8÷ṬØ»Ḳ¤,2ịÇƊṚK
Try it online!
Long by Jelly standards, but done from first principles.
Thanks to @JonathanAllan for saving 13 bytes through better understanding of string compression.
$endgroup$
$begingroup$
“£ṢtẒ⁽ẹ½MḊxɲȧėAṅ ɓaṾ¥D¹ṀẏD8÷ṬØ»Ḳ¤
would save 13 (Compress.dictionary looks for a leading space and has special handling for it).
$endgroup$
– Jonathan Allan
Mar 14 at 12:13
add a comment |
$begingroup$
Jelly, 115 114 101 97 bytes
%30%20¹0<?4Ḥ+ؽị“thstndrd”ṭ
“5<Ḟ’b4+28ÄŻ_@µ>0T,>0$ƇZṪµ1ịị“£ṢtẒ⁽ẹ½MḊxɲȧėAṅ ɓaṾ¥D¹ṀẏD8÷ṬØ»Ḳ¤,2ịÇƊṚK
Try it online!
Long by Jelly standards, but done from first principles.
Thanks to @JonathanAllan for saving 13 bytes through better understanding of string compression.
$endgroup$
Jelly, 115 114 101 97 bytes
%30%20¹0<?4Ḥ+ؽị“thstndrd”ṭ
“5<Ḟ’b4+28ÄŻ_@µ>0T,>0$ƇZṪµ1ịị“£ṢtẒ⁽ẹ½MḊxɲȧėAṅ ɓaṾ¥D¹ṀẏD8÷ṬØ»Ḳ¤,2ịÇƊṚK
Try it online!
Long by Jelly standards, but done from first principles.
Thanks to @JonathanAllan for saving 13 bytes through better understanding of string compression.
edited Mar 14 at 19:03
answered Mar 13 at 21:37
Nick KennedyNick Kennedy
89147
89147
$begingroup$
“£ṢtẒ⁽ẹ½MḊxɲȧėAṅ ɓaṾ¥D¹ṀẏD8÷ṬØ»Ḳ¤
would save 13 (Compress.dictionary looks for a leading space and has special handling for it).
$endgroup$
– Jonathan Allan
Mar 14 at 12:13
add a comment |
$begingroup$
“£ṢtẒ⁽ẹ½MḊxɲȧėAṅ ɓaṾ¥D¹ṀẏD8÷ṬØ»Ḳ¤
would save 13 (Compress.dictionary looks for a leading space and has special handling for it).
$endgroup$
– Jonathan Allan
Mar 14 at 12:13
$begingroup$
“£ṢtẒ⁽ẹ½MḊxɲȧėAṅ ɓaṾ¥D¹ṀẏD8÷ṬØ»Ḳ¤
would save 13 (Compress.dictionary looks for a leading space and has special handling for it).$endgroup$
– Jonathan Allan
Mar 14 at 12:13
$begingroup$
“£ṢtẒ⁽ẹ½MḊxɲȧėAṅ ɓaṾ¥D¹ṀẏD8÷ṬØ»Ḳ¤
would save 13 (Compress.dictionary looks for a leading space and has special handling for it).$endgroup$
– Jonathan Allan
Mar 14 at 12:13
add a comment |
$begingroup$
Google Sheets, 118 103 86 bytes
=day(A1+1)&mid("stndrdth",min(7,1+2*mod(mod(day(A1+1)-1,30),20)),2)&text(A1+1," mmmm")
I can't edit my comment so, here's a working version of the Google Sheets code.
Try it Online!
$endgroup$
add a comment |
$begingroup$
Google Sheets, 118 103 86 bytes
=day(A1+1)&mid("stndrdth",min(7,1+2*mod(mod(day(A1+1)-1,30),20)),2)&text(A1+1," mmmm")
I can't edit my comment so, here's a working version of the Google Sheets code.
Try it Online!
$endgroup$
add a comment |
$begingroup$
Google Sheets, 118 103 86 bytes
=day(A1+1)&mid("stndrdth",min(7,1+2*mod(mod(day(A1+1)-1,30),20)),2)&text(A1+1," mmmm")
I can't edit my comment so, here's a working version of the Google Sheets code.
Try it Online!
$endgroup$
Google Sheets, 118 103 86 bytes
=day(A1+1)&mid("stndrdth",min(7,1+2*mod(mod(day(A1+1)-1,30),20)),2)&text(A1+1," mmmm")
I can't edit my comment so, here's a working version of the Google Sheets code.
Try it Online!
edited Mar 14 at 20:48
answered Mar 14 at 20:10
ZylviijZylviij
1704
1704
add a comment |
add a comment |
$begingroup$
Red, 124 bytes
func[n][d: 1-1-1 + n - 1[rejoin[d/4 either 5 > t: d/4 % 30 % 20[pick[th st nd rd]t + 1]['th]]pick system/locale/months d/3]]
Try it online!
Adds n
- 1 days to 1-1-1 (1-Jan-2001) to form a date, than uses Arnauld's method to index into month suffixes. Too bad Red is 1-indexed, this requires additional tweaking. The good thing is that Red knows the names of the months :)
$endgroup$
add a comment |
$begingroup$
Red, 124 bytes
func[n][d: 1-1-1 + n - 1[rejoin[d/4 either 5 > t: d/4 % 30 % 20[pick[th st nd rd]t + 1]['th]]pick system/locale/months d/3]]
Try it online!
Adds n
- 1 days to 1-1-1 (1-Jan-2001) to form a date, than uses Arnauld's method to index into month suffixes. Too bad Red is 1-indexed, this requires additional tweaking. The good thing is that Red knows the names of the months :)
$endgroup$
add a comment |
$begingroup$
Red, 124 bytes
func[n][d: 1-1-1 + n - 1[rejoin[d/4 either 5 > t: d/4 % 30 % 20[pick[th st nd rd]t + 1]['th]]pick system/locale/months d/3]]
Try it online!
Adds n
- 1 days to 1-1-1 (1-Jan-2001) to form a date, than uses Arnauld's method to index into month suffixes. Too bad Red is 1-indexed, this requires additional tweaking. The good thing is that Red knows the names of the months :)
$endgroup$
Red, 124 bytes
func[n][d: 1-1-1 + n - 1[rejoin[d/4 either 5 > t: d/4 % 30 % 20[pick[th st nd rd]t + 1]['th]]pick system/locale/months d/3]]
Try it online!
Adds n
- 1 days to 1-1-1 (1-Jan-2001) to form a date, than uses Arnauld's method to index into month suffixes. Too bad Red is 1-indexed, this requires additional tweaking. The good thing is that Red knows the names of the months :)
edited Mar 14 at 8:49
answered Mar 14 at 8:35
Galen IvanovGalen Ivanov
7,24211034
7,24211034
add a comment |
add a comment |
$begingroup$
APL(NARS), 235 chars, 470 bytes
{k←↑⍸0<w←+v←(1-⍵),(12⍴28)+13561787⊤⍨12⍴4⋄k<2:¯1⋄d←1+v[k]-w[k]⋄(⍕d),({d∊11..13:'th'⋄1=10∣d:'st'⋄2=10∣d:'nd'⋄3=10∣d:'rd'⋄'th'}),' ',(k-1)⊃(m≠' ')⊂m←'January February March April May June July August September October November December'}
13561787 is the number that in base 4 can be summed to (12⍴28) for obtain the lenght of each month...
test:
f←{k←↑⍸0<w←+v←(1-⍵),(12⍴28)+13561787⊤⍨12⍴4⋄k<2:¯1⋄d←1+v[k]-w[k]⋄(⍕d),({d∊11..13:'th'⋄1=10∣d:'st'⋄2=10∣d:'nd'⋄3=10∣d:'rd'⋄'th'}),' ',(k-1)⊃(m≠' ')⊂m←'January February March April May June July August September October November December'}
⊃f¨1 2 3 365 60 11
1st January
2nd January
3rd January
31st December
1st March
11th January
$endgroup$
add a comment |
$begingroup$
APL(NARS), 235 chars, 470 bytes
{k←↑⍸0<w←+v←(1-⍵),(12⍴28)+13561787⊤⍨12⍴4⋄k<2:¯1⋄d←1+v[k]-w[k]⋄(⍕d),({d∊11..13:'th'⋄1=10∣d:'st'⋄2=10∣d:'nd'⋄3=10∣d:'rd'⋄'th'}),' ',(k-1)⊃(m≠' ')⊂m←'January February March April May June July August September October November December'}
13561787 is the number that in base 4 can be summed to (12⍴28) for obtain the lenght of each month...
test:
f←{k←↑⍸0<w←+v←(1-⍵),(12⍴28)+13561787⊤⍨12⍴4⋄k<2:¯1⋄d←1+v[k]-w[k]⋄(⍕d),({d∊11..13:'th'⋄1=10∣d:'st'⋄2=10∣d:'nd'⋄3=10∣d:'rd'⋄'th'}),' ',(k-1)⊃(m≠' ')⊂m←'January February March April May June July August September October November December'}
⊃f¨1 2 3 365 60 11
1st January
2nd January
3rd January
31st December
1st March
11th January
$endgroup$
add a comment |
$begingroup$
APL(NARS), 235 chars, 470 bytes
{k←↑⍸0<w←+v←(1-⍵),(12⍴28)+13561787⊤⍨12⍴4⋄k<2:¯1⋄d←1+v[k]-w[k]⋄(⍕d),({d∊11..13:'th'⋄1=10∣d:'st'⋄2=10∣d:'nd'⋄3=10∣d:'rd'⋄'th'}),' ',(k-1)⊃(m≠' ')⊂m←'January February March April May June July August September October November December'}
13561787 is the number that in base 4 can be summed to (12⍴28) for obtain the lenght of each month...
test:
f←{k←↑⍸0<w←+v←(1-⍵),(12⍴28)+13561787⊤⍨12⍴4⋄k<2:¯1⋄d←1+v[k]-w[k]⋄(⍕d),({d∊11..13:'th'⋄1=10∣d:'st'⋄2=10∣d:'nd'⋄3=10∣d:'rd'⋄'th'}),' ',(k-1)⊃(m≠' ')⊂m←'January February March April May June July August September October November December'}
⊃f¨1 2 3 365 60 11
1st January
2nd January
3rd January
31st December
1st March
11th January
$endgroup$
APL(NARS), 235 chars, 470 bytes
{k←↑⍸0<w←+v←(1-⍵),(12⍴28)+13561787⊤⍨12⍴4⋄k<2:¯1⋄d←1+v[k]-w[k]⋄(⍕d),({d∊11..13:'th'⋄1=10∣d:'st'⋄2=10∣d:'nd'⋄3=10∣d:'rd'⋄'th'}),' ',(k-1)⊃(m≠' ')⊂m←'January February March April May June July August September October November December'}
13561787 is the number that in base 4 can be summed to (12⍴28) for obtain the lenght of each month...
test:
f←{k←↑⍸0<w←+v←(1-⍵),(12⍴28)+13561787⊤⍨12⍴4⋄k<2:¯1⋄d←1+v[k]-w[k]⋄(⍕d),({d∊11..13:'th'⋄1=10∣d:'st'⋄2=10∣d:'nd'⋄3=10∣d:'rd'⋄'th'}),' ',(k-1)⊃(m≠' ')⊂m←'January February March April May June July August September October November December'}
⊃f¨1 2 3 365 60 11
1st January
2nd January
3rd January
31st December
1st March
11th January
edited Mar 14 at 9:10
answered Mar 14 at 7:38
RosLuPRosLuP
2,286514
2,286514
add a comment |
add a comment |
$begingroup$
C (gcc), 174 155 bytes
i;char a[99],*b="thstndrd";f(long x){x--;x*=86400;strftime(a,98,"%d %B",gmtime(&x));i=*a==49?0:a[1]-48;a[2]=b[i=i>3?0:i*2];a[3]=b[++i];x=*a==48?a+1:a;}
Try it online!
$endgroup$
add a comment |
$begingroup$
C (gcc), 174 155 bytes
i;char a[99],*b="thstndrd";f(long x){x--;x*=86400;strftime(a,98,"%d %B",gmtime(&x));i=*a==49?0:a[1]-48;a[2]=b[i=i>3?0:i*2];a[3]=b[++i];x=*a==48?a+1:a;}
Try it online!
$endgroup$
add a comment |
$begingroup$
C (gcc), 174 155 bytes
i;char a[99],*b="thstndrd";f(long x){x--;x*=86400;strftime(a,98,"%d %B",gmtime(&x));i=*a==49?0:a[1]-48;a[2]=b[i=i>3?0:i*2];a[3]=b[++i];x=*a==48?a+1:a;}
Try it online!
$endgroup$
C (gcc), 174 155 bytes
i;char a[99],*b="thstndrd";f(long x){x--;x*=86400;strftime(a,98,"%d %B",gmtime(&x));i=*a==49?0:a[1]-48;a[2]=b[i=i>3?0:i*2];a[3]=b[++i];x=*a==48?a+1:a;}
Try it online!
edited Mar 15 at 9:42
answered Mar 15 at 9:29
GPSGPS
33115
33115
add a comment |
add a comment |
$begingroup$
TSQL, 83 bytes
DECLARE @ datetime=4
-1PRINT format(@,'d'+left(substring('stndrd',day(@)%20*3-2,3)+'th',3)+' MMMM')
Abusing substring returns empty string when the input is out of range. Also abusing an integer can be assigned to a datetime while subtracting 1 in the code.
Try it out
$endgroup$
add a comment |
$begingroup$
TSQL, 83 bytes
DECLARE @ datetime=4
-1PRINT format(@,'d'+left(substring('stndrd',day(@)%20*3-2,3)+'th',3)+' MMMM')
Abusing substring returns empty string when the input is out of range. Also abusing an integer can be assigned to a datetime while subtracting 1 in the code.
Try it out
$endgroup$
add a comment |
$begingroup$
TSQL, 83 bytes
DECLARE @ datetime=4
-1PRINT format(@,'d'+left(substring('stndrd',day(@)%20*3-2,3)+'th',3)+' MMMM')
Abusing substring returns empty string when the input is out of range. Also abusing an integer can be assigned to a datetime while subtracting 1 in the code.
Try it out
$endgroup$
TSQL, 83 bytes
DECLARE @ datetime=4
-1PRINT format(@,'d'+left(substring('stndrd',day(@)%20*3-2,3)+'th',3)+' MMMM')
Abusing substring returns empty string when the input is out of range. Also abusing an integer can be assigned to a datetime while subtracting 1 in the code.
Try it out
edited Mar 19 at 12:00
answered Mar 18 at 11:32
t-clausen.dkt-clausen.dk
1,984314
1,984314
add a comment |
add a comment |
$begingroup$
Python 3, 95 Bytes
Datetimed it :P
from datetime import *;f=lambda s:(datetime(2019,1,1)+timedelta(days=s-1)).strftime("%d of %B")
Try it online!
New contributor
$endgroup$
1
$begingroup$
This doesn't produce the ordinal suffixes, and has leading zeroes in the day number. Theof
is also unnecessary
$endgroup$
– Jo King
Mar 19 at 12:10
add a comment |
$begingroup$
Python 3, 95 Bytes
Datetimed it :P
from datetime import *;f=lambda s:(datetime(2019,1,1)+timedelta(days=s-1)).strftime("%d of %B")
Try it online!
New contributor
$endgroup$
1
$begingroup$
This doesn't produce the ordinal suffixes, and has leading zeroes in the day number. Theof
is also unnecessary
$endgroup$
– Jo King
Mar 19 at 12:10
add a comment |
$begingroup$
Python 3, 95 Bytes
Datetimed it :P
from datetime import *;f=lambda s:(datetime(2019,1,1)+timedelta(days=s-1)).strftime("%d of %B")
Try it online!
New contributor
$endgroup$
Python 3, 95 Bytes
Datetimed it :P
from datetime import *;f=lambda s:(datetime(2019,1,1)+timedelta(days=s-1)).strftime("%d of %B")
Try it online!
New contributor
New contributor
answered Mar 18 at 20:45
KerosenicKerosenic
11
11
New contributor
New contributor
1
$begingroup$
This doesn't produce the ordinal suffixes, and has leading zeroes in the day number. Theof
is also unnecessary
$endgroup$
– Jo King
Mar 19 at 12:10
add a comment |
1
$begingroup$
This doesn't produce the ordinal suffixes, and has leading zeroes in the day number. Theof
is also unnecessary
$endgroup$
– Jo King
Mar 19 at 12:10
1
1
$begingroup$
This doesn't produce the ordinal suffixes, and has leading zeroes in the day number. The
of
is also unnecessary$endgroup$
– Jo King
Mar 19 at 12:10
$begingroup$
This doesn't produce the ordinal suffixes, and has leading zeroes in the day number. The
of
is also unnecessary$endgroup$
– Jo King
Mar 19 at 12:10
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
4
$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
Mar 13 at 15:29
5
$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
Mar 13 at 15:38
9
$begingroup$
Whoa, don't accept answers so quickly. Especially not wrong answers!
$endgroup$
– Adám
Mar 13 at 16:10
6
$begingroup$
You should add at least
11
(11th January) and21
(21st January) to the test cases.$endgroup$
– Arnauld
Mar 13 at 16:30
1
$begingroup$
And while you're editing test cases, maybe specify what exactly your test case format is. A couple of answerers have thought that
123=
was part of the required output. Or simply edit your test cases to read something like:365
gives31st December
$endgroup$
– Adám
Mar 13 at 16:36