mirror of
https://github.com/correl/euler.git
synced 2024-11-24 03:00:08 +00:00
Problem 019
git-svn-id: file:///srv/svn/euler@46 e5f4c3ec-3c0c-11df-b522-21efaa4426b5
This commit is contained in:
parent
da639adddb
commit
cd6bea96ee
1 changed files with 30 additions and 0 deletions
30
e019.py
Normal file
30
e019.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
class Day:
|
||||||
|
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY = range(7)
|
||||||
|
|
||||||
|
def is_leap_year(year):
|
||||||
|
return (year % 100 > 0 and year % 4 == 0) or (year % 400 == 0)
|
||||||
|
|
||||||
|
year = 1900
|
||||||
|
# 1/1/1900 was a Monday
|
||||||
|
first_day = Day.MONDAY
|
||||||
|
|
||||||
|
total = 0
|
||||||
|
while year < 2000:
|
||||||
|
year = year + 1
|
||||||
|
# Count last year's days to advance the starting weekday
|
||||||
|
days = 366 if is_leap_year(year - 1) else 365
|
||||||
|
# List the number of days in each month for this year
|
||||||
|
months = [
|
||||||
|
31,
|
||||||
|
29 if is_leap_year(year) else 28,
|
||||||
|
31, 30, 31, 30, 31, 31, 30, 31, 30, 31
|
||||||
|
]
|
||||||
|
first_day = (first_day + days % 7) % 7
|
||||||
|
sundays = 0
|
||||||
|
for m in range(len(months)):
|
||||||
|
days = sum(months[:m])
|
||||||
|
first_sunday = (7 - ((first_day + days % 7) % 7)) % 7 + 1
|
||||||
|
if first_sunday == 1:
|
||||||
|
total = total + 1
|
||||||
|
|
||||||
|
print 'Total months beginning on Sunday from 1/1/1901 to 12/31/2000: {0}'.format(total)
|
Loading…
Reference in a new issue