### Exercise in mod7 arithmetic: What is the probability that 6 Mar is a Thursday?

Rather than "What is the probability that today is a Thursday", I should have posed the question as "What is the probability that 6 Mar 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 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+k/4)%7 for k in range(100) for i in 0,5,3,1])`

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

6 Mar 2000 was a Mon, as was 2 Oct 2000, so its pattern is the same:

[6 Mar] Sun: 58, Mon: 56, Tue: 58, Wed: 57, Thu: 57, Fri: 58, Sat: 56

and the probability that 6 Mar is a Thu is 57/400, slightly lower than 1/7.

(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.
(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 `[time.strptime('6/Mar/{}'.format(y),'%d/%b/%Y').tm_wday for y in range(2000,2400)]` to count the day of the week for every 6/Mar from 2000-2399
(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
0 5 3 ... 3
5 ...     1
3 ...     6
1 ...     4
```
again with a lazy method
`Counter([2]+[(5*j+i)%7 for j in range(24) for i in 0,5,3,1])`
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 `[time.strptime('29/Feb/{}'.format(y),'%d/%b/%Y').tm_wday for y in range(2000,2400,4) if y not in (2100,2200,2300)]).`
The most recent 29 Feb 2012 was a Wed 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).