Created
April 13, 2012 22:57
-
-
Save yurivictor/2380671 to your computer and use it in GitHub Desktop.
Get the number of Friday the 13ths in the past 100 years
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
from datetime import * | |
from dateutil.rrule import * | |
from dateutil.relativedelta import * | |
def get_friday_the_13s(): | |
YEARS_AGO = 100 | |
TODAY = date.today() | |
YEARSAGO = TODAY + relativedelta(years=-YEARS_AGO) | |
fridays = list(rrule(DAILY, byweekday=(FR), dtstart=YEARSAGO, until=TODAY)) | |
friday13s = list(rrule(DAILY, bymonthday=13, byweekday=(FR), dtstart=YEARSAGO, until=TODAY)) | |
print 'In the past', YEARS_AGO, 'years, there have been', len(friday13s), 'Friday the 13ths.' | |
get_friday_the_13s() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment