Skip to content

Instantly share code, notes, and snippets.

@oshea00
Created February 1, 2017 22:18
Show Gist options
  • Save oshea00/5fda88ddbcf662338ed18781bccd5b34 to your computer and use it in GitHub Desktop.
Save oshea00/5fda88ddbcf662338ed18781bccd5b34 to your computer and use it in GitHub Desktop.
months = [0, 6, 2, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
def centuryOffset(c):
if c / 100 == 21:
return -2
if c / 100 == 20:
return 0
if c / 100 == 19:
return 1
if c / 100 == 18:
return 3
if c / 100 == 17:
return 5
def isleapyear(c):
if (c / 4) * c == c:
if (c / 100) * 100 == c:
if (c / 400) * 400 == c:
return True
else:
return False
else:
return True
else:
return False
def dow(m,d,yyyy):
isleap = isleapyear(yyyy)
coff = centuryOffset(yyyy)
monthoff = months[int(m)]
yy = yyyy - (yyyy / 100) * 100
yy += yy/4
yearcode = (yy % 7) + coff
leapoff = -1 if isleap is True else 0
if 0 < m < 3:
return (yearcode + monthoff + d + leapoff) % 7
else:
return (yearcode + monthoff + d) % 7
firstofmonthdows = [dow(1,m,y+1900) for y in range(0, 100) for m in range(1,13)]
print(len([d for d in firstofmonthdows if d == 0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment