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 Sim0000
from calendar import weekday, isleap, day_name
def most_frequent_days(year):
d = [weekday(year, 1, i) for i in range(1, 2 + isleap(year))]
return [day_name[i] for i in sorted(d)]
# Because 365 % 7 == 1, the most frequent weekday is the weekday
# of the 1/1 of the year. In leap year case, because 366 % 7 == 2,
# both 1/1 and 1/2 are the most frequent.
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"
March 22, 2016
Comments: