-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP019.py
More file actions
executable file
·53 lines (44 loc) · 1002 Bytes
/
P019.py
File metadata and controls
executable file
·53 lines (44 loc) · 1002 Bytes
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
46
47
48
49
50
51
52
53
#!/usr/bin/python
from math import floor
def isLeapYear(year):
if str(year)[-2:]== '00':
return year % 400 == 0
return year % 4 == 0
def daysInYear(year):
if isLeapYear(year):
return 366
return 365
def daysInMonth(month, year):
if month in [4, 6, 9, 11]:
return 30
elif month in [1, 3, 5, 7, 8, 10, 12]:
return 31
elif isLeapYear(year):
return 29
else:
return 28
def dayOfYear(month, day, year):
days = 0
for m in range(1, month):
days += daysInMonth(m, year)
return days + day
def daysSince1900(month, day, year):
days = 0
for y in range(1900, year):
days += daysInYear(y)
return days + dayOfYear(month, day, year)
def isSunday(month, day, year):
days = daysSince1900(month, day, year)
return days % 7 == 0
def numSundays(year):
count = 0
for m in range(1, 13):
if isSunday(m, 1, year):
count += 1
return count
def sundaysInCentury(year):
count = 0
for y in range(1901, year+1):
count += numSundays(y)
return count
print sundaysInCentury(2000)