2019 has the exact same calendar (i.e. all days of the week coincide) as 2013.
I noticed this by simply looking at the actual printed out calendars.
However, this made me wonder how to calculate in general, for a given year $Y_2$, the closest year $Y_1$ that had the exact same calendar.
In essence, I was trying to find $Y_1 < Y_2$, with $Y_1, Y_2 \in \mathbb{N} $ such that the number of days between Jan 1st $Y_1$ (included) and Jan 1st $Y_2$ (not included) was a multiple of 7.
[Not sufficient: see Edit 1 below]
The number of days between those two dates is:
$N_{Y_2-Y_1} = 365 \cdot (Y_2 - Y_1) + number \ of \ leap \ years$
For the number of leap years, I found this post, so I could write:
$N_{Y_2-Y_1} = 365 \cdot (Y_2 - Y_1) + \lfloor \frac{Y_2}{4} \rfloor - \lfloor \frac{Y_2}{100} \rfloor + \lfloor \frac{Y_2}{400} \rfloor - \lfloor \frac{Y_1}{4} \rfloor + \lfloor \frac{Y_1}{100} \rfloor - \lfloor \frac{Y_1}{400} \rfloor$
I applied this formula to a simple while
loop taking $Y_2$ as input, and checking one by one the years before that until it found one for which the number of days was exactly divisible by 7.
This may be satisfactory from a numerical point of view, and it shows that the smallest distance between calendar-identical years can be 5, 6, 7, 11 or 12, with rather different frequencies for the various cases, 6 being the most frequent, followed by 5 and 11, then 12, then 7.
[WRONG: see Edit 1 below]
However, it does not provide a 'closed form' for the calculation of $Y_1$ given $Y_2$.
I looked at posts and other resources describing equations with floor functions (e.g. this one and this one), and while I sort of understood the concept for the examples given in those posts and could reproduce it, I could not quite fit it to my case.
I wonder if anyone could please provide some guidance?
I started with a simplified case, assuming that all years divisible by 4 are leap years (in fact I did not even know that century years not multiple of 400 were not leap years). The equation is then:
$N_{Y_2-Y_1} = 365 \cdot (Y_2 - Y_1) + \lfloor \frac{Y_2}{4} \rfloor - \lfloor \frac{Y_1}{4} \rfloor$
For this quantity to be a multiple of 7, there must be an integer $i$ such that:
$365 \cdot (Y_2 - Y_1) + \lfloor \frac{Y_2}{4} \rfloor - \lfloor \frac{Y_1}{4} \rfloor = 7 \cdot i$
I.e., considering that $365 \cdot (Y_2 - Y_1) = 7 \cdot 52 \cdot (Y_2 - Y_1) + (Y_2 - Y_1)$:
$(Y_2 - Y_1) + \lfloor \frac{Y_2}{4} \rfloor - \lfloor \frac{Y_1}{4} \rfloor = 7 \cdot [i - 52 \cdot (Y_2 - Y_1)]$
The first doubt I have is: given that $i - 52 \cdot (Y_2 - Y_1)$ is an integer, can I replace it by another integer $j$, or does the fact that it contains my variables make this a wrong move?
I tried the methods described in the posts I linked above, namely substituting the quantities in each floor function with the sum of an integer + a 'fractional' quantity $\in [0,1)$, but I got rather knotted up, and in particular I could not eliminate the initial integer $i$, which however is not known a priori.
Could you please comment about my approach / suggest how I should proceed (for the moment focusing on the simplified case)?
Thanks!
EDIT 1 (after post by Hagen v E)
As pointed out by Hagen, even my numerical calculation was wrong, because it only checked that the starting weekday of $Y_1$ was the same as the starting weekday of $Y_2$, not that the years were both leap or both non-leap.
After adding the leap-match check to the script, it turned out (unless I'm mistaken again) that in each 400 years cycle there are:
- 182 cases where the closest identical year occurs 11 years earlier
- 109 cases where the closest identical year occurs 6 years earlier
- 76 cases where the closest identical year occurs 28 years earlier
- 18 cases where the closest identical year occurs 12 years earlier
- 15 cases where the closest identical year occurs 40 years earlier
In the simplified case (considering all years divisible by 4 as leap years):
- 200 cases where the closest identical year occurs 11 years earlier
- 100 cases where the closest identical year occurs 6 years earlier
- 100 cases where the closest identical year occurs 28 years earlier
EDIT 2 (putting together the suggestions from the other users)
Following up from bloodflea's post below, and extending the method to the actual case considering non-leap century years.
Please correct me if I'm wrong.
First, I define 3 conditions.
$a : \frac {Y_2}{400} = \lfloor \frac {Y_2}{400} \rfloor$
$b : \frac {Y_2}{100} = \lfloor \frac {Y_2}{100} \rfloor$
$c : \frac {Y_2}{4} = \lfloor \frac {Y_2}{4} \rfloor$
Expanding all possible cases, and taking into account that:
$a \to b \to c$
there are 4 possible (main) scenarios:
$A : c \land b \land a : Y_2 $ is a century leap year (like 2000)
$B : \bar c \land b \land a : Y_2 $ is a century non-leap year (like 1900)
$C : \bar c \land \bar b \land a : Y_2 $ is a non-century leap year (like 1960)
$D : \bar c \land \bar b \land \bar a : Y_2 $ is a non-century non-leap year (like 2019)
Given $Y_2$, I am looking for a function outputting $Y_1$ as defined above.
I define $\Delta = Y_2 - Y_1$.
In each case, each year in $\Delta$ 'brings' $364 = 7 \cdot 52$ days, plus either $1$ day (non-leap) or $2$ days (leap).
Thus $\Delta$ will be a suitable value when the sum of these 'added' days is a multiple of $7$ and both $Y_2$ and $Y_1$ are of the same 'type' (leap or non-leap).
Case A: ($Y_2$ century leap year)
The condition on the number of 'added' days is:
$\Delta + \lfloor \frac {\Delta}{4} \rfloor = 7 \cdot i, i \in \mathbb{N}^+, \Delta < 400$
As $Y_2$ is a leap year, the condition that both years are of the same type is:
$\Delta = 4 \cdot j, j \in \mathbb{N}^+, \Delta < 400$
Putting the two together:
$4 \cdot j + j = 7 \cdot i$
$5 \cdot j = 7 \cdot i$
$j = i + \frac 2 5 \cdot i$
The smallest $i$ for which this is true is $i = 5$, resulting in:
$j = 5 + 2 = 7$
$\Delta = 4 \cdot 7 = 28 < 400$
Case B ($Y_2$ century non-leap year)
The condition on the number of 'added' days is:
$\Delta + \lfloor \frac {\Delta}{4} \rfloor = 7 \cdot i, i \in \mathbb{N}^+, \Delta < 100$
As $Y_2$ is a non-leap year, the condition that both years are of the same type is:
$\frac {Y_1} 4 \ne integer, \Delta < 100$
$\frac {Y_2-\Delta} 4 \ne integer, \Delta < 100$
$\frac {-\Delta} 4 \ne integer, \Delta < 100$
$\Delta \ne 4 \cdot j, j \in \mathbb{N}^+, 0 < \Delta < 100$
I tried defining $\Delta$ as $4 \cdot j + 1$ etc, but I got nowhere, so I just tried out the first few values. $\Delta = 6$ was the first that satisfied the two conditions.
Case C ($Y_2$ non-century leap year)
Two sub-cases:
C.1. $100 \cdot \lfloor \frac {Y_2}{100} \rfloor$ is a leap year, i.e. $\frac 1 4 \cdot \lfloor \frac {Y_2}{100} \rfloor$ is an integer
C.2. $100 \cdot \lfloor \frac {Y_2}{100} \rfloor$ is a non-leap year, i.e. $\frac 1 4 \cdot \lfloor \frac {Y_2}{100} \rfloor$ is not an integer
[to be continued...]