-
-
Save ubernostrum/d8d2f29417c063e873506936996d6d56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
import datetime | |
import sys | |
DAYS_OF_WEEK = [ | |
"Monday", | |
"Tuesday", | |
"Wednesday", | |
"Thursday", | |
"Friday", | |
"Saturday", | |
"Sunday", | |
] | |
def weekday_frequency(month, day, start_year=1583, end_year=3000): | |
""" | |
For the given date (month/day combination), calculate and | |
return the frequency, in order, of that date falling on each day | |
of the week in the range of years given by start_year - end_year | |
(inclusive). | |
""" | |
current_year = start_year | |
histogram = collections.Counter({day: 0 for day in DAYS_OF_WEEK}) | |
while current_year <= end_year: | |
year_date = datetime.date(current_year, month, day) | |
histogram[DAYS_OF_WEEK[year_date.weekday()]] += 1 | |
current_year += 1 | |
return histogram.most_common() | |
if __name__ == "__main__": | |
if len(sys.argv) != 3: | |
sys.exit("Please provide numeric month and day arguments, in that order.") | |
month, day = map(int, sys.argv[1:]) | |
for weekday, count in weekday_frequency(month, day): | |
print(f"{weekday}: {count}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment