diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-08-11 18:42:52 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-08-11 18:42:52 +0200 |
| commit | 7b624de8e3e3637a07364f992c1d7e4185e4a872 (patch) | |
| tree | fdb9b0c3f9185b267f9f7bfb9cb4b0e4cdd8cc16 /python/19-counting_sundays.py | |
| download | project_euler-7b624de8e3e3637a07364f992c1d7e4185e4a872.tar.gz project_euler-7b624de8e3e3637a07364f992c1d7e4185e4a872.tar.bz2 project_euler-7b624de8e3e3637a07364f992c1d7e4185e4a872.zip | |
initial commit
Diffstat (limited to 'python/19-counting_sundays.py')
| -rw-r--r-- | python/19-counting_sundays.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/python/19-counting_sundays.py b/python/19-counting_sundays.py new file mode 100644 index 0000000..f018e05 --- /dev/null +++ b/python/19-counting_sundays.py @@ -0,0 +1,34 @@ +def month_days(index, leap_year): + if index == 2: + if leap_year: + return 29 + return 28 + if index in [4, 6, 9, 11]: + return 30 + return 31 + + +def is_leap_year(year): + if str(year)[2:] == '00' and year % 400 != 0: + return False + if year % 4 == 0: + return True + return False + +def next_day(current): + if current == 7: + return 1 + return current + 1 + +months = [x for x in range(1, 13)] +day = 1 +sundays_counter = 0 + +for year in range(1900, 2001): + for month in months: + for d in range(month_days(month, is_leap_year(year))): + if day == 7 and d == 0 and year >= 1901: + sundays_counter += 1 + day = next_day(day) + +print(sundays_counter) |
