Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First of The Most Frequent Weekdays solution in Creative category for The Most Frequent Weekdays by Oleg_Novikov
def most_frequent_days(year):
import calendar
q_ty_of_days = [0, 0, 0, 0, 0, 0, 0]
days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
answer = []
for month in range(1, 13):
calendar_of_month = calendar.monthcalendar(year, month)
for week in calendar_of_month:
for day_of_the_week in range(7):
if week[day_of_the_week]:
q_ty_of_days[day_of_the_week] += 1
start = 0
max_value = max(q_ty_of_days)
for i in range(q_ty_of_days.count(max_value)):
day = q_ty_of_days.index(max_value, start)
answer.append(days[day])
start = day + 1
return answer
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"
Sept. 13, 2018
Comments: