Skip to content

Instantly share code, notes, and snippets.

@zbstof
Created August 8, 2013 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zbstof/6184843 to your computer and use it in GitHub Desktop.
Save zbstof/6184843 to your computer and use it in GitHub Desktop.
m1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
m2 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
mon_sy = {
1: "January", 2: "February", 3: "March", 4: "April", 5: "May", 6: "June",
7: "July", 8: "August", 9: "September", 10: "October", 11: "November",
12: "December"}
leap = [year for year in range(1904, 2001, 4)]
def months():
for year in range(1901, 2001):
if year in leap:
for i, month in enumerate(m2):
yield year, i, month
else:
for i, month in enumerate(m1):
yield year, i, month
day = sum(m1) % 7
sundays = 0
for year, mon, days in months():
if day == 6:
sundays = sundays + 1
print year, mon_sy[mon + 1]
day = day + days
day = day % 7
print sundays
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment