Skip to content

Instantly share code, notes, and snippets.

@sysuin
Created December 30, 2018 08:35
Show Gist options
  • Save sysuin/550d90ba9d8cea7a993bc5cf78e4f49d to your computer and use it in GitHub Desktop.
Save sysuin/550d90ba9d8cea7a993bc5cf78e4f49d to your computer and use it in GitHub Desktop.
Write a program that calculates the day of the week for any particular date in the past or future.
test = int(input())
for i in range(test):
dmy = input().split()
d = int(dmy[0])
m = int(dmy[1])
y = int(dmy[2])
day = ["Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"]
red1 = ((y%400)//100)*5
red2 = (int(((y%100)-1)/4))
red3 = (y%100 - red2 -1)*1
red = (red1 + 2*red2 + red3)%7
if (y%4==0 & y%400==0):
month_leap = [0, 0, 31, 60, 91, 121, 152, 182, 213, 244,
274, 305, 335, 366]
total = (d + month_leap[m] + red)%7
print(day[total])
else:
month_nonleap = [0, 0, 31, 59, 90, 120, 151, 181, 212, 243,
273, 304, 334, 365]
total = (d + month_nonleap[m] + red)%7
print(day[total])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment