public
Created

MIT 6.189 from the first problem set, the optional Zeller Algorithm

  • Download Gist
zeller.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
def zeller(A,B,C,D):
if A == 1 or A == 2:
A+=10
C-=1
else:
A-=2
W = (13*A-1) / 5
X = C / 4
Y = D / 4
Z = W + X + Y + B + C - 2*D
R = Z % 7
if R < 0:
R += 7
if R == 0:
return "Sunday"
if R == 1:
return "Monday"
if R == 2:
return "Tuesday"
if R == 3:
return "Wednesday"
if R == 4:
return "Thursday"
if R == 5:
return "Friday"
if R == 6:
return "Saturday"
 
A = int(raw_input("what month are we talking? "))
B = int(raw_input("what is the day of the month? "))
C = int(raw_input("what year? Just the last two digits "))
D = int(raw_input("what century? "))
 
print zeller(A,B,C,D)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.