-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
What is "Day-number Month" format? I'm assuming it's "20th March"? Or is it "20 March"? That makes a pretty big difference, if you need ordinals. – Rɪᴋᴇʀ – 2019-03-13T15:28:51.553
4Also, 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? – Rɪᴋᴇʀ – 2019-03-13T15:29:20.913
Can we output native Date object that is builtin to our language, without converting it to a string? If we do have to convert it to a string, do we have to output in that exact format? – Embodiment of Ignorance – 2019-03-13T15:31:31.170
I believe input validation is not allowed in challenges, at least to a point.
– CG One Handed – 2019-03-13T15:37:55.5275As 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". – Adám – 2019-03-13T15:38:11.140
So is it
March 1st
or1st March
? – Draco18s no longer trusts SE – 2019-03-13T15:47:30.430The latter, I messed up. – Andrew – 2019-03-13T15:48:12.917
9Whoa, don't accept answers so quickly. Especially not wrong answers! – Adám – 2019-03-13T16:10:00.370
Whoops. I guess I'll check every answer and wait for a shorter one. – Andrew – 2019-03-13T16:11:04.610
This is 14 bytes in Dyalog APL 18.0:
– Adám – 2019-03-13T16:20:49.180'Doo Mmmm'∘⎕DN
but it hasn't been released yet ;-(When it releases, tell me. – Andrew – 2019-03-13T16:22:00.213
6You should add at least
11
(11th January) and21
(21st January) to the test cases. – Arnauld – 2019-03-13T16:30:58.6531And 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
– Adám – 2019-03-13T16:36:03.163I'm quite surprised this has not been asked before. Good question. – akozi – 2019-03-15T17:41:37.613