'_7×sε`UD3‹©12*+>₂*T÷®Xα©т%D4÷®т÷©4÷®·(O7%}D.•1Î㦕©sèsǝÀÐáÐÙ'sQi'œÙ뮦¦Qi’…‚Ž’ëQi’€Ÿ…Â’]u
Inputs in the format [dd,mm,yyyy]
; output format starts at Sunday (SMTWTFS
).
Try it online or verify all test cases.
Explanation:
Since 05AB1E has no Date builtins, we'll have to calculate the Day of the Week manually.
The general formula to do this is:
$${\displaystyle h=\left(q+\left\lfloor{\frac{13(m+1)}{5}}\right\rfloor+K+\left\lfloor{\frac{K}{4}}\right\rfloor+\left\lfloor{\frac{J}{4}}\right\rfloor-2J\right){\bmod{7}}}$$
Where for the months March through December:
- \$q\$ is the \$day\$ of the month (
[1, 31]
)
- \$m\$ is the 1-indexed \$month\$ (
[3, 12]
)
- \$K\$ is the year of the century (\$year \bmod 100\$)
- \$J\$ is the 0-indexed century (\$\left\lfloor {\frac {year}{100}}\right\rfloor\$)
And for the months January and February:
- \$q\$ is the \$day\$ of the month (
[1, 31]
)
- \$m\$ is the 1-indexed \$month + 12\$ (
[13, 14]
)
- \$K\$ is the year of the century for the previous year (\$(year - 1) \bmod 100\$)
- \$J\$ is the 0-indexed century for the previous year (\$\left\lfloor {\frac {year-1}{100}}\right\rfloor\$)
Resulting in the day of the week \$h\$, where 0 = Saturday, 1 = Sunday, ..., 6 = Friday.
Source: Zeller's congruence
The implementation of this formula in the code below is:
`UD3‹©12*+>₂*T÷®Xα©т%D4÷®т÷©4÷®·(O7%
'_7× '# Push string "_______"
s # Swap to get the (implicit) input-list
ε # Map over each date:
# Determine its day of the week:
` # Push the day, month, and year to the stack
U # Pop and save the year in variable `X`
D # Duplicate the month
3‹ # Check if the month is below 3 (Jan. / Feb.),
# resulting in 1 or 0 for truthy/falsey respectively
© # Store this in variable `®` (without popping)
12* # Multiply it by 12 (either 0 or 12)
+ # And add it to the month
# (This first part was to make Jan. / Feb. 13 and 14)
> # Month + 1
₂* # Multiplied by 26
T÷ # Integer-divided by 10
® # Push month<3 from variable `®` again
Xα # Take the absolute difference with the year
© # Store this potentially modified year as new `®` (without popping)
т% # mYear modulo-100
D4÷ # mYear modulo-100, integer-divided by 4
®т÷©4÷ # mYear integer-divided by 100, and then integer-divided by 4
®·( # mYear integer-divided by 100, doubled, and then made negative
O # Take the sum of all values on the stack
7% # And then take modulo-7 to complete the formula, resulting in 0 for
# Saturday, 1 for Sunday, and [2, 6] for [Monday, Friday]
}D # After the map: duplicate the list of integers
.•1Î㦕 # Push compressed string "ssmtwtf"
© # Store it in variable `®` (without popping)
s # Swap so the duplicated list of integers is at the top
è # Index each into this string
s # Swap so the list of integers is at the top again
ǝ # Insert the characters at these indices inside the "_______" string
À # Rotate it once towards the left
Ð # Triplicate this result
á # Only leave the letters of the top copy
Ð # Triplicate that as well
„ssQi '# Pop one copy, and if it's equal to "ss":
'œÙ '# Push dictionary string "weekend"
뮦¦Qi # Else-if it's equal to `®` minus its first two characters ("mtwtf"):
’…‚Ž’ # Push dictionary string "weekday"
ëQi # Else-if the string remained the same after only leaving letters:
’€Ÿ…Â’ # Push dictionary string "allweek"
] # Close all if-else statements
u # Uppercase the result
# (after which this is output implicitly)
See this 05AB1E tip of mine (sections How to use the dictionary? and How to compress strings not part of the dictionary?) to understand why .•1Î㦕
is "ssmtwtf"
; 'œÙ
is "weekend"
; ’…‚Ž’
is "weekday"
; and ’€Ÿ…Â’
is "allweek"
.