Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for The Most Frequent Weekdays by kapasunka
import datetime
array = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
def most_frequent_days(year):
"""
List of most frequent days of the week in the given year
"""
start_day = datetime.datetime(year,1,1).weekday()
leap_year = year%4 == 0 and (year%100 != 0 or year%400 == 0)
days = 366%7 if leap_year else 365%7
result_list = sorted([(i + start_day)%7 for i in range(days)])
return list(map(lambda x: array[x], result_list))
if __name__ == '__main__':
# These "asserts" using only for self-checking and not necessary for auto-testing
#assert most_frequent_days(1900) == ['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"
Jan. 15, 2019