Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Most Frequent Weekdays by vasily_bortnikov
import datetime, calendar
def most_frequent_days(year):
startWeekday = datetime.date(year, 1, 1).weekday()
endWeekday = datetime.date(year, 12, 31).weekday()
if startWeekday > endWeekday:
weekdays = list(range(endWeekday+1)) + list(range(startWeekday,7))
else:
weekdays = list(range(startWeekday,endWeekday + 1))
return [calendar.day_name[i] for i in weekdays]
if __name__ == '__main__':
print("Example:")
print(most_frequent_days(1084))
# These "asserts" are used for self-checking and not for an auto-testing
assert most_frequent_days(1084) == ['Tuesday', 'Wednesday']
assert most_frequent_days(1167) == ['Sunday']
assert most_frequent_days(1216) == ['Friday', 'Saturday']
assert most_frequent_days(1492) == ['Friday', 'Saturday']
assert most_frequent_days(1770) == ['Monday']
assert most_frequent_days(1785) == ['Saturday']
assert most_frequent_days(212) == ['Wednesday', 'Thursday']
assert most_frequent_days(1) == ['Monday']
assert most_frequent_days(2135) == ['Saturday']
assert most_frequent_days(3043) == ['Sunday']
assert most_frequent_days(2001) == ['Monday']
assert most_frequent_days(3150) == ['Sunday']
assert most_frequent_days(3230) == ['Tuesday']
assert most_frequent_days(328) == ['Monday', 'Sunday']
assert most_frequent_days(2016) == ['Friday', 'Saturday']
print("Coding complete? Click 'Check' to earn cool rewards!")
Oct. 23, 2019
Comments: