¦WΘ1š-1šVтFY`2ô0Kθ4ÖUD2Qi\28X+ë<7%É31α}‹iY¬>0ëY1¾ǝDÅsD12‹i>1ë\1Dǝ¤>2}}ǝVY})DJIJk18+£35.£¬.•4ιõ÷‡o‹ƶ¸•2ôs`UÐ3‹12*+>13*5÷s3‹Xα©т%D4÷®т÷©4÷®·()DćsćsO7%._s€нT‰J«7ô»
Input in the format [day, month, year]
. Output with leading 0
s for single-digit days, and lowercase mo
through su
(+1 byte can be added if titlecase is mandatory).
Try it online or verify all test cases.
Holy shit.. This might be my new record for longest 05AB1E answer, and then I include some very complex ascii-art challenges I did... >.> EDIT: Hmm ok, almost.. ;p
Important note: 05AB1E doesn't have any builtins for Date objects or calculations. The only builtin regarding dates it has is today's year/month/day/hours/minutes/seconds/microseconds.
So because of that, almost all of the code you see are manual calculations to calculated the previous and next days (including transition over years and keeping in mind the leap years), and calculating the day of the week by using Zeller's congruence.
Huge parts of the code are copied from this earlier 05AB1E answer of mine, which will also be relevant for the explanation below.
Explanation:
We start by going to the first day of the previous month:
¦ # Remove the first item (the days) from the (implicit) input
W # Get the minimum (without popping the list itself)
# (since the year is guaranteed to be above 1599, this is the month)
Θ # Check if its exactly 1 (1 if 1, 0 if in the range [2,31])
1š # Prepend a 1 as list (so we now have either [1,1] or [1,0]
- # Subtract this from the month and year
1š # And prepend a 1 for the day
V # Pop and store this first day of the previous month in variable `Y`
Then I use that date as start date, and calculate the next 100 days:
тF # Loop 100 times:
Y`2ô0Kθ4ÖUD2Qi\28X+ë<7%É31α}‹iY¬>0ëY1¾ǝDÅsD12‹i>1ë\1Dǝ¤>2}}ǝV
# Calculate the next day in line
# (see the linked challenge above for a detailed explanation of this)
Y # And leave it on the stack
}) # After the loop: wrap the entire stack into a list, which contains our 100 days
Then, with the input-date as the middle, I only leave the 17 before and 17 after that input-date from the list:
DJ # Duplicate the 100 dates, and join the day/month/year together to strings
IJ # Push the input, also joined together
k # Get the 0-based index of the input in this list
# (the joins are necessary, because indexing doesn't work for 2D lists)
18+ # Add 18 to this index (18 instead of 17, because the index is 0-based)
£ # Only leave the first index+18 items from the 100 dates
35.£ # Then only leave the last 35 items
Now we have our 35 days. Next step is to calculate the day of the week, and create the header of the output-table:
¬ # Get the first date of the list (without popping the list itself)
.•4ιõ÷‡o‹ƶ¸• # Push compressed string "sasumotuwethfr"
2ô # Split it into chunks of size 2
s # Swap to get the first date again
`UÐ3‹12*+>13*5÷s3‹Xα©т%D4÷®т÷©4÷®·()DćsćsO7%
# Calculate the day of the week (sa=0; su=1; ...; fr=6)
# (see the linked challenge above for a detailed explanation of this)
._ # Rotate the list of strings that many times
See this 05AB1E tip of mine (section How to compress strings not part of the dictionary?) to understand why .•4ιõ÷‡o‹ƶ¸•
is "sasumotuwethfr"
.
Then we create the days to fill the table itself based on our earlier created list of dates. Which we'll merge together with the header. After which we can print the final result:
s # Swap to get the list of dates again
€н # Only leave the first item of each date (the days)
T‰ # Take the divmod 10 of each
J # Join those divmod results together
# (we now have leading 0s for single-digit days)
« # Merge this list together with the header list
7ô # Split it into chunks of size 7
» # Join each inner list by spaces, and then each string by newlines
# (and output the result implicitly)