-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem019.py
More file actions
45 lines (34 loc) · 1.09 KB
/
problem019.py
File metadata and controls
45 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Copyright 22017 Keval Khara kevalk@bu.edu
'''
Using the Gaussian Algorithm to caluclate the day of the week:
w = (d+floor(2.6*m-0.2)+y+floor(y/4)+floor(c/4)-2*c) mod 7
Y = year - 1 for January or February
Y = year for other months
d = day (1 to 31)
m = shifted month (March = 1, February = 12)
y = last two digits of Y
c = first two digits of Y
w = day of week (Sunday = 0, Saturday = 6)
'''
from math import floor
def day_of_week(year, month, day):
d = day
m = (month - 3) % 12 + 1
if m > 10:
Y = year - 1
else:
Y = year
y = Y % 100
c = (Y - (Y % 100)) / 100
w = (d + floor(2.6 * m - 0.2) + y + floor(y/4) + floor(c/4) - 2*c) % 7
return int(w)
# Compute the number of months starting on a given day of the week in a century
def months_start_range(day,year_start,year_end):
total = 0
for year in range(year_start, year_end + 1):
for month in range(1,13):
if day_of_week(year, month, 1) == day:
total += 1
return total
total = months_start_range(0,1901,2000)
print(total)