From 672eb30f3e544777009e198c34b93aa2d064f056 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Tue, 4 May 2010 18:41:33 +0000 Subject: [PATCH] Created main() function in e019, missed it in the last commit. git-svn-id: file:///srv/svn/euler@64 e5f4c3ec-3c0c-11df-b522-21efaa4426b5 --- e019.py | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/e019.py b/e019.py index d7d2e35..79a355a 100644 --- a/e019.py +++ b/e019.py @@ -20,30 +20,31 @@ class Day: 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 +def main(): + 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 + 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) + print 'Total months beginning on Sunday from 1/1/1901 to 12/31/2000: {0}'.format(total) if __name__ == '__main__': main()