3 ms·
Ignoring leap years, the pattern within a century [1] is that the calendar for year Y, where Y is the 2-digit year, can next be reused in: Y+6 if Y is of the f
by tzs 7y ago
Ignoring leap years, the pattern within a century [1] is that the calendar for year Y, where Y is the 2-digit year, can next be reused in:
Y+6 if Y is of the form 4N or 4N+1
Y+11 if Y is of the form 4N+2
Y+5 if Y is of the form 4N+3
If you start at a 4N year, this takes you to a 4N+2 year, then 4N+1 year, then a 4N+3 year, and then back to a 4N year, so you'll step through the century in steps of 6, 11, 6, 5, and repeat.
So, for 2019, 19 = 4x4+3, and we at at the add 5 stage of that 6, 11, 6, 5 pattern, and so (ignoring leap years) we get the same calendar in 2019+5 = 2024, 2024+6 = 2030, 2030+11 = 2041, 2041+6 = 2047, 2047+5 = 2052, 2052+6 = 2058, 2058+11 = 2069, 2069+6 = 2075, 2075+5 = 2080, 2080+6 = 2086, and 2080+11 = 2097.
Now it is time to stop ignoring leap year. 2019 is not a leap year, so strike from that list any leap years, leaving 2030, 2041, 2047, 2058, 2069, 2075, 2086, and 2097.
Note you can also go backward. 2019-6 = 2013, 2013-11 = 2002.
Another way to do this, perhaps simpler, is to note that two 2-digit years, Y1 and Y2, in the same century have the same calendar (ignoring leap years) if Y1 + Y1//4 == Y2 + Y2//4 mod 7.
The smallest year for which Y + Y//4 == K mod 7, for K=0,1,2...,6 is: 0, 1, 2, 3, 9, 4, 5.
So, back to 2019. 19 + 19//4 == 2 mod 7, which we see from the prior paragraph first occurs in 2002. That's a 4N+2, so we start the 6, 11, 6, 5 pattern at 11. Get the next three years that match 2002 from that pattern: 2013, 2019, 2024.
You could continue the cycle from there to finish off the century, buy perhaps easier is to note that the whole pattern of calendars and leap years repeats every 28 years.
28 years added to 2002, 2013, 2019, 2024 gives 2030, 2041, 2047, and 2052. Another 28 years gives 2058, 2069, 2075, and 2080. Next is 2086 and 2097.
Let's bust out of our confinement to the current century. Century C has the same calendars as century C+4, so our 2019 calendar will work in 2402, 2413, 2419, and so on.
Using 2000 as the base, whenever we cross a century boundary within the current 400 century span, it is like adding 5 to the Y + Y//4 value.
For 2019 we were using 19 + 19//4 == 2 mod 7 for our target. When we cross into the 2100s we pick up 5, and so need to subtract 5 from that 2 to compensate. Remember, we do all that mod 7, and the result is 4. In the 2100 century, then, we are looking for years with Y + Y//4 == 4 mod 7. As we saw 6 paragraphs back, 2109 would be the first such year.
2109 is a 4N+1 year, which puts us at the second 6 in the 6, 11, 6, 5 pattern, giving us 2115, 2120, 2126 as the other matching years in the first 28. Repeat those every 28 to fill with the 2100s.
Don't forget to delete the leap years!
Note: the calendars for the leap years are only off during January and February. You can go ahead and use, for example, the 2019 calendar in 2024 for March through December.
[1] for our purposes, century == fullyear//100, in Python 3. E.g., the current century is [2000, 2099].
- I_complete_me 7y agoThis reminds me of the efforts I made to answer the following question from a Soviet puzzle book I happened upon."Does New Year's Day fall more often on a Sunday or a Saturday?". I will leave the working out of the answer to the curious.