Problem 19
This commit is contained in:
parent
e4e8007494
commit
9a33095ecc
72
0019.py
Normal file
72
0019.py
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
target = 171
|
||||||
|
|
||||||
|
def is_leap_year (year):
|
||||||
|
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
|
||||||
|
|
||||||
|
def days_since_1900 (year, month = 1, day = 1):
|
||||||
|
days = 0
|
||||||
|
|
||||||
|
for y in range(1900, year):
|
||||||
|
if (is_leap_year(y)):
|
||||||
|
days += 366
|
||||||
|
else:
|
||||||
|
days += 365
|
||||||
|
|
||||||
|
for m in range(1, month):
|
||||||
|
days += get_days_in_month(m, year)
|
||||||
|
|
||||||
|
days += day - 1
|
||||||
|
|
||||||
|
return days
|
||||||
|
|
||||||
|
days_in_month = [
|
||||||
|
None,
|
||||||
|
31,
|
||||||
|
28,
|
||||||
|
31,
|
||||||
|
30,
|
||||||
|
31,
|
||||||
|
30,
|
||||||
|
31,
|
||||||
|
31,
|
||||||
|
30,
|
||||||
|
31,
|
||||||
|
30,
|
||||||
|
31,
|
||||||
|
]
|
||||||
|
|
||||||
|
week_days = [
|
||||||
|
'mon',
|
||||||
|
'tue',
|
||||||
|
'wed',
|
||||||
|
'thu',
|
||||||
|
'fri',
|
||||||
|
'sat',
|
||||||
|
'sun',
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_days_in_month (month, year):
|
||||||
|
days = days_in_month[month]
|
||||||
|
|
||||||
|
if (month == 2 and is_leap_year(year)):
|
||||||
|
return days + 1
|
||||||
|
|
||||||
|
return days
|
||||||
|
|
||||||
|
def get_day_of_week (year, month, day):
|
||||||
|
days = days_since_1900(year, month, day)
|
||||||
|
|
||||||
|
rest = days % 7
|
||||||
|
|
||||||
|
return week_days[rest]
|
||||||
|
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
for year in range(1901, 2001):
|
||||||
|
for month in range(1, 13):
|
||||||
|
if (get_day_of_week(year, month, 1) == 'sun'):
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
print(count)
|
||||||
|
print(count == target)
|
||||||
Loading…
Reference in New Issue
Block a user