Created
November 10, 2014 02:49
-
-
Save chipbell4/6c4c8798039fda11e6ba to your computer and use it in GitHub Desktop.
My Solution For Recycle Calendar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import datetime | |
| def yearsShareCalendar(year1, year2): | |
| # years match if their starting days and ending days of the week match | |
| year1_start = datetime.datetime(year1, 1, 1) | |
| year2_start = datetime.datetime(year2, 1, 1) | |
| year1_end = datetime.datetime(year1, 12, 31) | |
| year2_end = datetime.datetime(year2, 12, 31) | |
| return year1_start.weekday() == year2_start.weekday() and year1_end.weekday() == year2_end.weekday() | |
| def nextRecycleYear(year): | |
| next_year = year + 1 | |
| # just stop at some magic number we know we won't cross | |
| while next_year < 3000: | |
| if yearsShareCalendar(year, next_year): | |
| return next_year | |
| next_year += 1 | |
| N = int(input().strip()) | |
| for i in range(N): | |
| year = int(input().strip()) | |
| next_recycle_year = nextRecycleYear(year) | |
| print('Calendar for {0} can next be reused in {1}.'.format(year, next_recycle_year)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment