Euler 0019
The Problem:
How many Sundays fell on the first of the month between Jan 1 1901 and Dec 31 2000?
Considerations:
There is for sure a number theory mathematical way of handling this... but...
Approach:
What if we just imported a python calendar module and counted how many Sundays were between then and now?
The Code:
import calendar
year = 1901
end_year = 2000
sunday_first_days = 0
for i in range(year, end_year + 1):
this_year = calendar.Calendar().yeardayscalendar(i,12)
for year in this_year:
for month in year:
for week in month:
if week[6] == 1:
sunday_first_days += 1
print(sunday_first_days)
No comments to display
No comments to display