Skip to content

Instantly share code, notes, and snippets.

@ubernostrum
Created January 9, 2023 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ubernostrum/d8d2f29417c063e873506936996d6d56 to your computer and use it in GitHub Desktop.
Save ubernostrum/d8d2f29417c063e873506936996d6d56 to your computer and use it in GitHub Desktop.
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