One of the New Year cards from Ghent University (Belgium) teaches us that we could have reused any calendar of 2013, 2002 or 1991 in the year 2019.
But how long must we keep the calendar of 2018 before it can be used again? Well, we have to wait until 2029. If you think this is way too long, you can already reuse the 2018 calendar during the first two months of 2024 (a leap year).
We can reuse the calendar of year $$y_1$$ in year $$y_2$$ if all corresponding days fall on the same date (day and month) and weekday if we run through both calendars day by day. Your task:
Write a function first_difference that takes two years $$y_1$$ (int) and $$y_2$$ (int). The function must return the first day of year $$y_2$$ (datetime.date) that differs from the corresponding day of year $$y_1$$ if we run through the calendars of $$y_1$$ and $$y_2$$ day by day starting at the 1st of January. The function must return the value None if both years don't have any corresponding days that differ.
Write a function reuse_calendar that takes a year $$y$$ (int). The function also has a second optional parameter previous that may take a Boolean value (bool, default value: False). If the parameter previous takes the value False, the function must return the next year (int) in which we can reuse the calendar of year $$y$$. If the parameter previous takes the value True, the function must return the previous year (int) whose calendar can be reused in year $$y$$.
Write a function reuse_calendars that takes a year $$y$$ (int) and an integer $$n \in \mathbb{N}_0$$ (int). The function also has a third optional parameter previous that may take a Boolean value (bool, default value: False). If the parameter previous takes the value False, the function must return a list (list) containing the next $$n$$ years (int, in chronological order) in which we can reuse the calendar of year $$y$$. If the parameter previous takes the value True, the function must return a list (list) containing the previous $$n$$ years (int, in reverse chronological order) whose calendar can be reused in year $$y$$.
>>> first_difference(2018, 2019)
datetime.date(2019, 1, 1)
>>> first_difference(2018, 2024)
datetime.date(2024, 2, 29)
>>> first_difference(2018, 2029)
>>> reuse_calendar(2018)
2029
>>> reuse_calendar(2018, True)
2007
>>> reuse_calendar(2019, previous=False)
2030
>>> reuse_calendar(2019, previous=True)
2013
>>> reuse_calendars(2018, 10)
[2029, 2035, 2046, 2057, 2063, 2074, 2085, 2091, 2103, 2114]
>>> reuse_calendars(2018, 10, True)
[2007, 2001, 1990, 1979, 1973, 1962, 1951, 1945, 1934, 1923]
>>> reuse_calendars(2019, 10, previous=False)
[2030, 2041, 2047, 2058, 2069, 2075, 2086, 2097, 2109, 2115]
>>> reuse_calendars(2019, 10, previous=True)
[2013, 2002, 1991, 1985, 1974, 1963, 1957, 1946, 1935, 1929]
Apparently we only need 14 calendars this century.
calendar | can be reused in |
---|---|
2001 | 2007, 2018, 2029, 2035, 2046, 2057, 2063, 2074, 2085, 2091 |
2002 | 2013, 2019, 2030, 2041, 2047, 2058, 2069, 2075, 2086, 2097 |
2003 | 2014, 2025, 2031, 2042, 2053, 2059, 2070, 2081, 2087, 2098 |
2004 | 2032, 2060, 2088 |
2005 | 2011, 2022, 2033, 2039, 2050, 2061, 2067, 2078, 2089, 2095 |
2006 | 2017, 2023, 2034, 2045, 2051, 2062, 2073, 2079, 2090 |
2008 | 2036, 2064, 2092 |
2009 | 2015, 2026, 2037, 2043, 2054, 2065, 2071, 2082, 2093, 2099 |
2010 | 2021, 2027, 2038, 2049, 2055, 2066, 2077, 2083, 2094, 2100 |
2012 | 2040, 2068, 2096 |
2016 | 2044, 2072 |
2020 | 2048, 2076 |
2024 | 2052, 2080 |
2028 | 2056, 2084 |