Euler Problem 19 asks:
‘research for yourself.
‘ * 1 Jan 1900 was a Monday.
‘ * 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.
‘ * A leap year occurs on any year evenly divisible by 4, but not on a
‘century unless it is divisible by 400.
‘How many Sundays fell on the first of the month during the twentieth
‘century (1 Jan 1901 to 31 Dec 2000)?
Wow. First thought: Euler actually got the century right. Math-minded indeed. Second thought: I need a day counter, a week counter, a month counter, a leap year checker. That’s a lot of conditionals. No wonder this is here. Third thought: I’m doing this in Excel. Piece of cake. This may be the only one aimed right at us, if not intentionally. Here’s my code. Ran in under a second.
Dim Start As Date
Dim Answer As Long
Dim T As Single
T = Timer
Start = DateSerial(1901, 1, 1)
Do While Start < DateSerial(2001, 1, 1)
If Weekday(Start) = vbSunday And Day(Start) = vbSunday Then
Answer = Answer + 1
Start = Start + 1
Debug.Print Answer; ” Time:”, Timer – T
Coded it up. It ran the first time, and I checked in with the right answer. I was feeling so good until I saw the pencil and paper approach of those who’d solved it …100 years with 12 months per year over 7 days