Date to Day
Ported from my C++ code. Outputs the day given the date as input. Probably horrible python, this is my first ever python script :)
#!/usr/bin/python def is_leap_year(year) : if(year%100 == 0 and year%400 != 0) : return 0 if(year%4 != 0) : return 0 return 1 def step_1(year) : century = year//100+1 if(century%4 == 0) : return 0 if(century%4 == 1) : return 6 if(century%4 == 2) : return 4 if(century%4 == 3) : return 2 def step_2(year, month) : if(not is_leap_year(year)) : last_leap_year = year while(not is_leap_year(last_leap_year)) : last_leap_year = last_leap_year-1 return (((last_leap_year%100)//4)*5+(year-last_leap_year)+1) else : temp = (((year%100)//4)*5) if(month > 2) : return temp+1 return temp def step_3(month, date) : if(month==1) : return date if(month==2) : return 3+date if(month==3) : return 3+date if(month==4) : return 6+date if(month==5) : return 1+date if(month==6) : return 4+date if(month==7) : return 6+date if(month==8) : return 2+date if(month==9) : return 5+date if(month==10): return date if(month==11): return 3+date if(month==12): return 5+date date = int(raw_input()) month = int(raw_input()) year = int(raw_input()) day = 0 day += step_1(year) day += step_2(year, month) day += step_3(month, date) if(day%7 == 0) : print "Saturday" if(day%7 == 1) : print "Sunday" if(day%7 == 2) : print "Monday" if(day%7 == 3) : print "Tuesday" if(day%7 == 4) : print "Wednesday" if(day%7 == 5) : print "Thursday" if(day%7 == 6) : print "Friday"

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Download this code in plain text format here
Comments: