Exercise in mod7 arithmetic: What is the probability that 4 Oct is a Thursday?

Recall that the rule for leap years is every four years, except on the century, but every fourth century, so since 365=1 mod7, the mod7 number of days in 400 years is 400 + 100 - 4 + 1 = 497 = 0 mod7. That means any pattern of day of the week occurrences for any date is frozen in, and will repeat every 400 years.

For example, 1 Oct 2000 was a Sun, In 2001 it was a Mon (and goes one day forward each non-leap year, and two days forward each leap year), so labeling Sun-Sat by 0-6, the first 100 year pattern for 1 Oct is

0123 5601 3456 1234 6012 4560 ... 1234  (total of 25 groups of 4, to 2099)
There are no leap years at 2100, 2200, 2300 so it continues:
5601 3456 ... 6012   (2100-2199)
3456 1234 ... 4560   (2200-2299)
1234 6012 ... 2345   (2300-2399)
and 1 Oct 2400 will again be a Sunday, at which point the cycle repeats.

We could count this analytically without much difficulty, but since it's a one-liner we use the "lazy" method

Counter([(i+k+int(k/4))%7 for i in (0,5,3,1) for k in range(100)])

which gives

[1 Oct] Sun: 56, Mon: 58, Tue: 57, Wed: 57, Thu: 58, Fri: 56, Sat: 58

If 1 Oct occurs on a Sun 56 times, that means that 2 Oct occurs on a Mon 56 times, and 3 Oct occurs on a Tue 56 times, and so on. Similarly, if 1 Oct occurs on a Mon 58 times, that means that 2 Oct occurs on a Tue 58 times, and 3 Oct occurs on a Wed 58 times, and so on. The remaining days are thus given by inserting an additional offset by j for j=1,...,6:

[2 Oct] Sun: 58, Mon: 56, Tue: 58, Wed: 57, Thu: 57, Fri: 58, Sat: 56
[3 Oct] Sun: 56, Mon: 58, Tue: 56, Wed: 58, Thu: 57, Fri: 57, Sat: 58
[4 Oct] Sun: 58, Mon: 56, Tue: 58, Wed: 56, Thu: 58, Fri: 57, Sat: 57
[5 Oct] Sun: 57, Mon: 58, Tue: 56, Wed: 58, Thu: 56, Fri: 58, Sat: 57
[6 Oct] Sun: 57, Mon: 57, Tue: 58, Wed: 56, Thu: 58, Fri: 56, Sat: 58
[7 Oct] Sun: 58, Mon: 57, Tue: 57, Wed: 58, Thu: 56, Fri: 58, Sat: 56

and the probability that 4 Oct is a Thu is 58/400, slightly higher than 1/7.

Comments:
(1) Since the number of days in 400 years is 0 mod 7, that means there are the same number of Sun/Mon/Tues/Wed/Thu/Fri/Sat in every 400 year cycle (each occurs (400*365 + 97)/7 = 20871 times)
(2) The number of times any given date is a Thursday will be 57,58,56,58,56,58,57 according to its mod 7 character.
(3) The even lazier method uses
Counter([datetime(y, 10, 4).isoweekday() for y in range(2000,2400)])
to count the day of the week for every 4/Oct from 2000-2399 (note .isoweekday() returns 1-7 for Mon-Sun, which is better than .weekday(), which returns 0-6 for Mon-Sun)
(4) Every date other than 29 Feb occurs 400 times, and 29 Feb occurs 97 times.

We can do the same for the leap day: 29 Feb 2000 was a Tue, so in 2004 it was a Sun, in 2008 a Fri, ... : it goes up by 5 mod7 each four years until Wed in 2096, then 2100 it doesn't happen, then Fri in 2104, continuing 5 days forward each year until Mon in 2196; then Wed in 2204 til Sat in 2296; then Mon in 2304 til Thu in 2396. The pattern is

2             (2000)
0 5 3 ... 3   (2004-2096)
5 ...     1   (2104-2196)
3 ...     6   (2204-2296)
1 ...     4   (2304-2396)
again with a lazy method
Counter([2]+[(5*i+j)%7 for i in (0,5,3,1) for j in range(24)])
giving
[29 Feb] Sun: 13, Mon: 15, Tue: 13, Wed: 15, Thu: 13, Fri: 14, Sat: 14

(equivalently we could have checked that these numbers balance the above to ensure that each day of the week occurs 20871 times in 400 years, or used the even lazier method
Counter([datetime(y, 2, 29).isoweekday() for y in range(2000,2400,4) if y not in (2100,2200,2300)])
The most recent 29 Feb 2016 was a Mon and that happens with probability 15/97, the least probable days for 29 Feb to occur are Thu/Tue/Sun with probability 13/97 (and next occur, respectively, in 2024, 2028, and 2032).

Yet more comments:

(1) The probability that a given date occurs on the day it does can be determined by an analog of Conway's "Doomsday rule" for determining the day of the week on which a date occurs. For example, 3 Oct 2000 (seven days before the "doomsday" at 10/10) falls on a Tue (the anchor day for the 21st century), and from the above that occurs 56 times every 400 years. That means every other post Feb date that year also occurs on its day of the week the same 56 times, up to and including Feb dates of the following year. To determine the number of times that date occurs on any other day of the week, we just move across the row of the table, 56 58 57 57 58 56 58, so that if a date that year fell on a Thu, the number of times that it occurs on Sun is three over, at the second 57. To determine the number of times that a given post Feb date occurs on the day that it does in any other year 2000 + y this century, calculate (y + int(y/4))mod 7 and move that number of times across the row. So for 2016, move (16 + 4)mod7=6 to the right, and learn that post Feb dates during 2016 all occur 58 times on the day of the week they occurred. Again moving to the left or right gives their number of occurrences on other days of the week. So a date that occurs on a Thu (after leap day) that year occurred 57 times on a Sun and 57 times on a Mon. (For Jan/Feb dates just use the result of the preceding year, or equivalently for non-leap years just subtract 1 from the mod 7 result and move one fewer step to the right, in leap years substract 2 from that result.) Starting 1 Mar 2017 and through 28 Feb 2018, dates occurred 56 times on their weekday during that period (then shift to 58, as is the case currently, and so on).

(2) The continued fraction approximation to the actual ratio of orbital (time to vernal equinoxes) and rotational periods, is currently about 365.242374 (those periods are roughly independent, depending on chaotic initial conditions, and though they can synchronize as for the moon and mercury, for earth that would happen on a much longer timescale).
So the current heuristic of every four years except multiples of 100 but multiples of 400 gives an average of (400*365 + 4*24 + 1 )/400 = 365 97/400 = 365.2425 days per year, and the accident is that 97 = 6 mod 7 cancels the (400*365) mod 7 = 1 (plus the accident that it was once decided that the earth took six days to create plus a day of rest to make a 7 day week).
But since it's only an approximation, that too will be off by as much as a day eventually, and the .000126 day/year mismatch means that in about 8000 years it would be off by about a day, hence the 19th century suggestion to make multiples of 4000 not leap years.
So while the probability of 6 Mar being Thu is not 1/7 on the 400 year timeframe, it could become closer on the timescale of many tens of thousands of years (in accord with intuition that the ratio of periods shouldn't have come out to correspond to an exactly truncated continued fraction).
But (according to the Leap_year wikipedia page) uncertainties in the changes in the earth's rotation and orbital rates means the mismatch can't be accurately enough predicted on the 4000 year timeframe to make the adjustment certain (though by my quick calculation neither the day getting longer by 1.5 ms per 100 years, or year getting shorter by 0.53 s per 100 years have much of an effect in anything less than millions of years, ditto things like the 1.8 microsecond /day shortening in length of day caused by the most recent Japan earthquake, but I'm likely missing something).