Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for The Most Frequent Weekdays by Rounin
days = ['Mon','Tues','Wednes','Thurs','Fri','Satur','Sun']
def isLeapYear(year):
return year % 400 == 0 or (year % 100 != 0 and year % 4 == 0)
def most_frequent_days(year):
currentyear = 2017
startday = 6
while currentyear < year:
startday += (2 if isLeapYear(currentyear) else 1)
startday -= (7 if startday >= 7 else 0)
currentyear += 1
while currentyear > year:
startday -= (2 if isLeapYear(currentyear-1) else 1)
startday += (7 if startday < 0 else 0)
currentyear -= 1
weekdays = sorted([(startday)%7] + ([(startday+1)%7] if isLeapYear(year) else []))
return list(map(lambda day: days[day]+'day', weekdays))
if __name__ == '__main__':
# These "asserts" using only for self-checking and not necessary for auto-testing
assert most_frequent_days(2399) == ['Friday'], "1st example"
assert most_frequent_days(1152) == ['Tuesday', 'Wednesday'], "2nd example"
assert most_frequent_days(56) == ['Saturday', 'Sunday'], "3rd example"
assert most_frequent_days(2909) == ['Tuesday'], "4th example"
Aug. 5, 2017