A couple weeks ago I wrote a post about the year share component of calculating the day of the week. To calculate the day of the week, you need to add the day of the week, a constant for the month, and the year share. Calculating year share is not that hard, but it’s the hardest step to carry out in your head.
The year share of a date y is
⌊5y/4⌋ % 7
where y is the last two digits of a year. There’s no need to multiply by 5, since you could compute
(y + ⌊y/4⌋) % 7
but this still takes some effort if y is large.
The earlier post gave nine different ways to compute the year share, and the easiest in my opinion is method #6:
- Round y down to the most recent leap year and remember how much you had to round down. Call that amount r.
- Let t be the tens value and u the units value.
- Return (2t − u/2 + r) % 7.
In symbols,
- Let y‘ = 4 ⌊y/4⌋ and r = y − y‘.
- Let t = ⌊y’/10⌋ and u = y‘ % 10.
- Return (2t − u/2 + r) % 7.
This method has a longer description but is easier to carry out mentally as the following examples illustrate.
Examples
Let y = 97. Here are the calculations required by the direct method.
- ⌊y/4⌋ = 24
- 97 + 24 = 121
- 121 % 7 = 2
Here are the calculations required by the second method.
- y‘ = 96 and r = 1.
- t = 9 and u = 6.
- (2*9 − 3 + 1) % 7 = 2
The former requires adding two 2-digit numbers. The latter requires doubling a single digit number and subtracting another single digit number.
The former requires reducing a 3-digit number mod 7 and the latter requires reducing a 2-digit number mod 7. Furthermore, the 2-digit number is never more than 18.
Proof
To prove that the two methods are equivalent we have to prove
⌊5y/4⌋ ≡ 2t − u/2 + r mod 7
which is kinda messy. The way t, u, and r are defined prevent this from being a simple algebraic calculation.
We can verify that
⌊5y/4⌋ ≡ 2t − u/2 + r mod 7
for y = 0, 1, 2, … 19 by brute force then prove the rest by induction. We’ll show that if the congruence holds for y then it holds for y + 20.
Suppose you increase y by 20. Then ⌊5y/4⌋ increases by 25. The value of t increases by 2, and the values of u and r remain unchanged, so the right side increases by 4. Since 25 % 7 = 4, the congruence still holds.
Another proof:
– Firstly, it’s enough to prove this for r=0, because the remainder r simply gets added in both cases. (We can write this down more formally, but it’s easier to just “see” than to explain.)
– So we can assume that y is a multiple of 4, namely y = 10t + u, and we want to prove that 5y/4 ≡ 2t − u/2 (mod 7), or equivalently (multiplying by 4) that 5y ≡ 8t − 2u, or equivalently (substituting y) that 5(10t + u) ≡ 8t – 2u. Well, mod 7, we can see that 50≡8 (≡1), and 5≡-2, so this is true.
% equal remainder?
Yes