Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #'Friday 13ths since 1700' Lister
- #for Python 2.x
- #by Dominic D. McGough
- #Friday, 23rd June, 2017
- def weekDay(year, month, day):
- offset = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
- week = ['Sunday',
- 'Monday',
- 'Tuesday',
- 'Wednesday',
- 'Thursday',
- 'Friday',
- 'Saturday']
- afterFeb = 1
- if month > 2: afterFeb = 0
- aux = year - 1700 - afterFeb
- # dayOfWeek for 1700/1/1 = 5, Friday
- dayOfWeek = 5
- # partial sum of days between current date and 1700/1/1
- dayOfWeek += (aux + afterFeb) * 365
- # leap year correction
- dayOfWeek += aux / 4 - aux / 100 + (aux + 100) / 400
- # sum monthly and day offsets
- dayOfWeek += offset[month - 1] + (day - 1)
- dayOfWeek %= 7
- return week[dayOfWeek]
- import datetime
- now = datetime.datetime.now()
- thisYear = now.year
- count = 0
- for year in range(1700, 2017+1):
- for month in range(1, 12+1):
- if weekDay(year, month, 13) == "Friday":
- print (str(13) + "/" + str(month) + "/" + str(year))
- count +=1
- print("There's been " + str(count) + " Friday 13ths since 1700!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement