05AB1E,175个 174 172 171 160 字节
¦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ô»
输入格式[day, month, year]
。输出与领先的0
S表示个位数天,小写mo
通过su
(如果首字母大写是强制性的,可以添加1字节)。
在线尝试或验证所有测试用例。
这可能是我最长的05AB1E答案的新记录,然后我做了一些非常复杂的ascii-art挑战...>> 编辑:嗯,好了,几乎.. p
重要说明: 05AB1E没有任何内置对象可用于Date对象或计算。关于日期的唯一内置函数是今天的年/月/日/小时/分钟/秒/秒/微秒。
因此,因此,您看到的几乎所有代码都是手动计算,用于计算前几天和后几天(包括经过几年的过渡并记住the年),并使用Zeller的全等值来计算星期几。
该代码的大部分都从我先前的05AB1E答案中复制而来,这也与以下说明有关。
说明:
我们从上个月的第一天开始:
¦ # 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`
然后,我将该日期用作开始日期,并计算接下来的100天:
т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
然后,以输入日期为中间,我只从列表中保留该输入日期之前的17和之后的17:
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
现在我们有35天了。下一步是计算星期几,并创建输出表的标题:
¬ # 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
看到这个05AB1E尖矿(部分如何压缩字符串不是字典的一部分吗?)理解为什么.•4ιõ÷‡o‹ƶ¸•
是"sasumotuwethfr"
。
然后,我们根据之前创建的日期列表来创建日期以填充表格本身。我们将其与标题合并在一起。之后,我们可以打印最终结果:
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)