Counting Sundays, Mondays, …
Thirty days has September,
April, June and November.
All the rest have thirty-one,
Saving February alone,
Which has twenty-eight, rain or shine.
And on leap years, twenty-nine.
You are also told that 1 Jan 1900 was a Monday, and that a leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.
Taken together this means that there are 146,097 days in 400 years, which corresponds to exactly 20,871 weeks. This result implies that the calendar repeats after 400 years, so 1 Jan 2300 will be a Monday too.
The Puzzle
Solving this puzzle involves counting how often things fall on particular days of the week during one 400 year cycle. Specifically let's introduce the following counts:
| a(d) |
The 31st of a month falls on day d. |
| b(d) |
The 13th of a month falls on day d. |
| c(d) |
Euler's birthday falls on day d. |
| e(d) |
The 29th of February falls on day d. |
| f(d) |
The 30th of a month falls on day d. |
For example, you will find that c(Fri) = 58, which means that of the 400 birthdays Euler would have enjoyed had he lived between 1900 and 2300, 58 of them fall on a Friday.
To find the cache calculate:
a(Sat) * (b(Fri) - b(Sat)) * (c(Sat) * c(Mon) + c(Sun)),
and,
e(Mon) * a(Fri) + f(Tue).