05AB1E、81 79 78 76 75 74 73 71 70 69 バイト
•ΘÏF•ºS₂+.¥-D0›©ÏθDT‰ć≠*4šß„—ÊØ3ôsè¨ð”……‚應…ä†ï€¿…Ë…ê†Ä…æ…Ì…Í”#®OèJ
@Grimyのおかげで-9バイト。
@JonathanAllanのJelly answerで使用したstandard the
トリックのおかげで-1バイト。 th,st,nd,rd
オンラインそれを試してみたり、すべての可能なテストケースを確認してください。
説明:
•ΘÏ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
T‰ # Take the divmod-10 of this day: [day//10, day%10]
ć # Extract the head; pop and push the remainder-list and head: [day%10], day//10
≠ # Check whether the day//10 is NOT 1 (0 if day//10 == 1; 1 otherwise)
* # Multiply that by the [day%10] value
4š # Prepend a 4 to this list
ß # Pop and push the minimum of the two (so the result is one of [0,1,2,3,4],
# where the values are mapped like this: 1..3→1..3; 4..9→4; 10..19→0; 20..23→0..3; 24..29→4; 30,31→0,1)
…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)
この05AB1Eのヒントを参照して、理由を理解してください。
- (セクション辞書の使用方法?)
”……‚應…ä†ï€¿…Ë…ê†Ä…æ…Ì…Í”
は"December January February March April May June July August September October November"
- (セクション辞書の使用方法?)
…thŠØ
は"th standards"
- (セクション大きな整数を圧縮する方法?)
•ΘÏF•
は5254545