← Back to challenges

Next Palindromic Date

PythonHardalgorithmsdates

Instructions

The 2nd of February 2020 is a palindromic date in both dd/mm/yyyy and mm/dd/yyyy format (02/02/2020).

February 2, 2020 is the only 2-digit month and day palindromic date that will occur in the 21st century. The next occurrence of a 2-digit month and day palindromic date will be December 12, 2121, which is exactly 101 years from the last occurrence. 101 is also a palindrome. Between the years, 3030 and 9090, exactly 1010 years separate each occurrence of a 2-digit month and day palindromic date.

Given a date in mm/dd/yyyy format and the number of years to scan, return a list containing palindromic dates in mm/dd/yyyy format that are palindromic in both dd/mm/yyyy and mm/dd/yyyy format.

Examples

palindromic_dates("01/01/2020", 100) ➞ ["02/02/2020"]

palindromic_dates("01/01/2020", 102) ➞ ["02/02/2020", "12/12/2121"]

palindromic_dates("01/01/9000", 200) ➞ ["09/09/9090"]

Notes

This is an adaptation of the Palindromic Date Challenge.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.