Ð3‹12*+>₂*T÷s3‹Xα©т%D4÷®т÷©4÷®·(O7%Θ
Here we go again. 05AB1E has no date builtins, so everything is done manually. This solution is a derivative of my answer here.
Takes both inputs separated, the \$month\$ as first input and \$year\$ as second.
Try it online or verify all test cases.
Explanation:
The general formula to calculate the Day of the Week manually 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 in the day of the week \$h\$, where 0 = Saturday, 1 = Sunday, ..., 6 = Friday.
Source: Zeller's congruence
Since we only care about \$q=1\$, we can use that to golf 2 bytes. With the formula above, the result would be \$2\$ for Mondays (and thus requiring a leading $
to push both 1 AND the input-month; as well as a trailing 2Q
to check if the result equal 2). But if we remove the \$q+\$ part, the result would be \$1\$ for Mondays (in which case we can use the implicit input-month, removing the $
; and also use the ==1
builtin Θ
instead of 2Q
).
Ð # Triplicate the (implicit) input-month
3‹ # Check if the month is below 3 (Jan. / Feb.),
# resulting in 1 or 0 for truthy/falsey respectively
12* # Multiply this 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
s3‹ # Check if the month is below 3 again (resulting in 1 / 0)
Iα # Take the absolute difference with the second input-year
© # Store this potentially modified year in the register
т% # 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 Sunday, and [1, 6] for [Monday, Saturday]
Θ # Check if this is equal to 1 (thus a Monday)
# (after which the result is output implicitly)
Note that I've also used \$\left\lfloor{\frac{26(m+1)}{10}}\right\rfloor\$ instead of \$\left\lfloor{\frac{13(m+1)}{5}}\right\rfloor\$, since 05AB1E has a 1-byte builtin for both 26
and 10
(₂
and T
respectively), saving a byte on the 13
.
[year, month]
". That implies to me a rigid input format (how else would a rigid input format be expressed?). I agree with what I think is your implication that the challenge would be better with the usual default I/O rules. I think OP should clarify this. @Adám \$\endgroup\$