Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import math
def findDayOfWeek(month, day, year):
monthCode = getMonthCode(month, year)
yearCode = getYearCode(year)
dayOfWeekNumber = day + monthCode + yearCode
daysOfWeek = dict({
0 : 'Saturday',
1 : 'Sunday',
2 : 'Monday',
3 : 'Tuesday',
4 : 'Wednesday',
5 : 'Thursday',
6 : 'Friday'
})
dayOfWeek = daysOfWeek[dayOfWeekNumber % 7]
return dayOfWeek
def getMonthCode(month, year):
monthCodes = dict({
'january' : 1,
'february' : 4,
'march' : 4,
'april' : 0,
'may' : 2,
'june' : 5,
'july' : 0,
'august' : 3,
'september' : 6,
'october' : 1,
'november' : 4,
'december' : 6
})
if(isLeapYear(year)):
monthCodes['january'] -= 1
monthCodes['february'] -= 1
return monthCodes[month.lower()]
def isLeapYear(year):
if(year % 400 == 0):
return True
if(year % 100 == 0):
return False
if(year % 4 == 0):
return True
return False
def getYearCode(year):
century = year // 100
centuryCode = 6 - 2 * (century % 4)
yy = year - 100 * century
yearCode = yy + yy // 4 + centuryCode
return yearCode
def checkDec25(year, maxYears):
# dow = day of week
dowOfDec25 = []
maxYear = year + maxYears
checkYear = year
while(checkYear < maxYear): # the 401st day will equal the 1st one
dow = findDayOfWeek('December', 25, checkYear)
dowOfDec25.append(dow)
checkYear += 1
return dowOfDec25
def arrayWithYears():
arr = checkDec25(2000, 400)
i = 0
while i < len(arr):
year = str(2000 + i)
arr[i] = year + ": " + arr[i]
i += 1
return arr
# uncomment the line below to print a list of days of week in the 400 year span of Dec 25
print(arrayWithYears())
def findNumberOfWednesdays(lst, year, maxYears):
count = 0
i = 0
dowOfDec25 = checkDec25(year, maxYears)
while (i < len(dowOfDec25)):
if dowOfDec25[i] == 'Wednesday':
count += 1
i += 1
return count
def main():
print(findNumberOfWednesdays(checkDec25(2000, 400), 2000, 400))
print('of')
print(400)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.