3 ms·
To go from "any" century, you can also memorize "2053", which is the days in a 4-year cycle: 2000 = 2 = tuesday; 2100 = 0 = sunday; 2200 = 5 = friday; 2300 = 3
by kseistrup 7y ago
To go from "any" century, you can also memorize "2053", which is the days in a 4-year cycle: 2000 = 2 = tuesday; 2100 = 0 = sunday; 2200 = 5 = friday; 2300 = 3 = wednesday.
For years other than the centuries, we need to add an offset. Given the year CCXX, we have:
(a, b) = divmod(XX, 12)
c = b // 4
offset = a + b + c
doomsday = start + offset
E.g., for 2020 (XX == 20) we get:
start = 2 # from the "2053" rule
(a, b) = divmod(20, 12) # (1, 8)
c = b // 4 # 2
offset = 1 + 8 + 2 = 4 (mod 7)
doomsday = start + offset # 2 + 4 = 6 = saturday
- ikeboy 7y agoThe "add 11" trick in my comment is easier to remember and apply than dividing by 12 and taking remainders.
- kseistrup 7y agoI guess we have different perceptions of which way is the easiest. There might even be methods we haven't heard about yet.
- tzs 7y agoI like my current method [1], while only requires addition, doubling, and a couple of conditional increments or additions. Even if you don't bother doing any mod 7 reduction along the way, you never have to deal with a number above 32. With both divide by 12 and odd 11, I would find myself occasionally making a goof when dealing with years near the end of centuries. [1] https://news.ycombinator.com/item?id=21926543 https://news.ycombinator.com/item?id=21926543