Created
February 1, 2021 08:00
-
-
Save kirenotneb/2086cac46f0f47096b3bb77e169aee4a to your computer and use it in GitHub Desktop.
Prime Friday calculator
This file contains hidden or 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
from datetime import date, timedelta | |
# This is a static set of all prime Month and plus Day (2 digits) integers. Since it's static we retain this set | |
# for all comparisons rather than compute it every time. | |
def isPrime(candidate): | |
primeSet = [101,103,107,109,113,127,131,211,223,227,229,307,311,313,317,331,401,409,419,421, | |
503,509,521,523,601,607,613,617,619,701,709,719,727,733,809,811,821,823,827,829,907,911,919,929, | |
1009,1013,1019,1021,1031,1103,1109,1117,1123,1129,1201,1213,1217,1223,1229,1231] | |
return candidate in primeSet | |
today = date.today() | |
week = timedelta(weeks=1) | |
# Determine the next Friday. | |
fridayDiff = 4 - date.weekday(today) | |
if fridayDiff >= 0: | |
# If it's Friday or earlier in the week just add the days | |
nextFriday = today + timedelta(days = fridayDiff) | |
else: | |
# If we are past Friday then move a week ahead and back up to Friday. | |
nextFriday = today + timedelta(days = 7 + fridayDiff) | |
# Find a year's worth of Fridays | |
for i in range(1,52): | |
n = nextFriday + (week * i) | |
# Cast the combination of ordinal month with 2 digit day as an integer | |
dateInt = int(n.month.__str__() + n.strftime('%d')) | |
# If the date is "prime" print it | |
if isPrime(dateInt): | |
print(n.ctime()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment