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 Y2, the closest year Y1 that had the exact same calendar.
In essence, I was trying to find Y1<Y2, with Y1,Y2∈N such that the number of days between Jan 1st Y1 (included) and Jan 1st Y2 (not included) was a multiple of 7.
[Not sufficient: see Edit 1 below]
The number of days between those two dates is:
NY2−Y1=365⋅(Y2−Y1)+number of leap years
For the number of leap years, I found this post, so I could write:
NY2−Y1=365⋅(Y2−Y1)+⌊Y24⌋−⌊Y2100⌋+⌊Y2400⌋−⌊Y14⌋+⌊Y1100⌋−⌊Y1400⌋
I applied this formula to a simple while
loop taking Y2 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 Y1 given Y2.
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:
NY2−Y1=365⋅(Y2−Y1)+⌊Y24⌋−⌊Y14⌋
For this quantity to be a multiple of 7, there must be an integer i such that:
365⋅(Y2−Y1)+⌊Y24⌋−⌊Y14⌋=7⋅i
I.e., considering that 365⋅(Y2−Y1)=7⋅52⋅(Y2−Y1)+(Y2−Y1):
(Y2−Y1)+⌊Y24⌋−⌊Y14⌋=7⋅[i−52⋅(Y2−Y1)]
The first doubt I have is: given that i−52⋅(Y2−Y1) 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 ∈[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 Y1 was the same as the starting weekday of Y2, 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:Y2400=⌊Y2400⌋
b:Y2100=⌊Y2100⌋
c:Y24=⌊Y24⌋
Expanding all possible cases, and taking into account that:
a→b→c
there are 4 possible (main) scenarios:
A:c∧b∧a:Y2 is a century leap year (like 2000)
B:ˉc∧b∧a:Y2 is a century non-leap year (like 1900)
C:ˉc∧ˉb∧a:Y2 is a non-century leap year (like 1960)
D:ˉc∧ˉb∧ˉa:Y2 is a non-century non-leap year (like 2019)
Given Y2, I am looking for a function outputting Y1 as defined above.
I define Δ=Y2−Y1.
In each case, each year in Δ 'brings' 364=7⋅52 days, plus either 1 day (non-leap) or 2 days (leap).
Thus Δ will be a suitable value when the sum of these 'added' days is a multiple of 7 and both Y2 and Y1 are of the same 'type' (leap or non-leap).
Case A: (Y2 century leap year)
The condition on the number of 'added' days is:
Δ+⌊Δ4⌋=7⋅i,i∈N+,Δ<400
As Y2 is a leap year, the condition that both years are of the same type is:
Δ=4⋅j,j∈N+,Δ<400
Putting the two together:
4⋅j+j=7⋅i
5⋅j=7⋅i
j=i+25⋅i
The smallest i for which this is true is i=5, resulting in:
j=5+2=7
Δ=4⋅7=28<400
Case B (Y2 century non-leap year)
The condition on the number of 'added' days is:
Δ+⌊Δ4⌋=7⋅i,i∈N+,Δ<100
As Y2 is a non-leap year, the condition that both years are of the same type is:
Y14≠integer,Δ<100
Y2−Δ4≠integer,Δ<100
−Δ4≠integer,Δ<100
Δ≠4⋅j,j∈N+,0<Δ<100
I tried defining Δ as 4⋅j+1 etc, but I got nowhere, so I just tried out the first few values. Δ=6 was the first that satisfied the two conditions.
Case C (Y2 non-century leap year)
Two sub-cases:
C.1. 100⋅⌊Y2100⌋ is a leap year, i.e. 14⋅⌊Y2100⌋ is an integer
C.2. 100⋅⌊Y2100⌋ is a non-leap year, i.e. 14⋅⌊Y2100⌋ is not an integer
[to be continued...]
Answer
First. Assuming your year is between more than 28 years away from a year divisible by 100 by not divisible be 400. (This will hold for the years 1829−1871,1929−2071,2129−2179 etc.)
For these span of years every year with 28 years before and 28 years later, it will hold that every four years will be a leap year.
Non-leap years will have 365=52∗7+1 days so each consecutive year will normally start one day later than the next. However the year after a leap year will occur two days after the previous year.
If you compare year n to year n+k and and if there are j leap years between n and k then the year will start k+j days later.
Every 28 years the entire calendar system starts over again because 28 years will have 7 leap years and 28+7=35=5∗7 so the calendar will start on the same day and will be a leap year if the first year was a leap year and won't be a leap year if the year wasn't a leap year.
So. Year n....
Case 1: Year n is a leap year. The calendar will repeat in 28 years and was the same 28 years ago.
Case 2: Year n is one year more than a leap year. n+6 will have one leap year between them (n+3) and so 6+1=7 so calendar n+6 will start on the same day and will not be a leap year so the calendars will be the same.
Year n−5 will be a leap year and not the same calendar. n−6 will have two leap years between them (n−1,n−5) and will start 6+2=8 earlier. n−11 will have three leap years between them (n−1,n−5,n−9) and so will start 11+3=14=2∗7 days earlier and will be the same calendar.
Case 3: n is two years past a leap year.
n+5 is not the same date because there is one leap year between them so the calendars or off by 5+1=6 days. n+6 is not the same calendar. There is one leap year between the so 6+1=7 and they start on the same day, but n+6 is a leap year. We must go further. n+11 will have 3 leap years between them (n+2,n+6,n+10 and thus will start 11+3=14=2∗7 days later and will be the same calendar.
n−5 isn't the same. (One leap year and 5 days isn't a multiple of 7.) Nor is n−6 (it's a leap year). But n−11 will have three leap years (n−2,n−6,n−10) and so will be 11+3=14 days offset and the calendars will be the same.
Case 4: n is 3 years past a leap year (like 2019 is)
Then n+5 is a leap year n+6 has two leap years between and n+11 will have 3 leap years (n+1,n+5,n+9) and so be offset by 14 and have the same calendar.
So 2030 will be the next year with the same calendars.
And n−6 will have one leap year between them n−3 and so be offset by 6+1=7 days and have the same calender. So 2013 had the same.
Monkey Wrench. Years divisible by 100 by not by 400 do not have leap days and they throw the system off.
But again we can calculate those much the same.
No comments:
Post a Comment