Have you ever heard of a palindrome? It’s a word, phrase, sentence (or more) that’s spelled exactly the same way backward and forward. Here are a few well known palindromes:

race car A man, a plan, a canal, Panama! I prefer pi Dammit, I’m mad! Ma is as selfless as I am Never odd or even

There’s also a concept of a word level palindrome, where if you reverse a sequence of words, you end up with the same sequence of words you started with. Here are a few cute examples (none of which are original):

King, are you glad you are king? Says Mom, “What do you do?” – You do what Mom says. You know, I did little for you, for little did I know you. Please me by standing by me please. Blessed are they that believe that they are blessed. Escher, drawing hands, drew hands drawing Escher.

You can also have palindromic dates. If we write any date using the format MMDDYYYY, you get a string of eight digits (for example, today’s date would be written “05232021″). A palindromic date is any date for which the eight digit string looks the same whether written backward or forward.

Today’s date is not a palindrome because “05232021” is not the same as “12023250”. How about this one: January 2, 2010? Is that a palindrome? Let’s see - written forward that would be “01022010″ and written backward it would be “01022010″. Yup, that’s a palindrome.

Got it? Ok, now you’re ready for today’s challenge: Tell me the most recent palindromic date before January 2, 2010. Extra credit if you can give me the two most recent palindromic dates before 01/02/2010.

Spoiler:

Let’s work our way backward, in years, from 2021. 2021 backwards is 1202, which is a

2009 doesn’t work because when written backwards it gives us an invalid month (90). Same story for 2008 through 2002 (month numbers 80, 70, …, 20). But 2001 gives us both a valid month (10) and day of month (02). That gives us the first answer: October 2, 2001 (10022001) is the most recent palindromic date before 01/02/2010.

Let’s work our way backward, in years, from 2010. 2009 doesn’t work because when written backwards it gives us an invalid month (90). Same story for 2008 through 2002 (month numbers 80, 70, …, 20). But 2001 gives us both a valid month (10) and day of month (02). That gives us the first answer: October 2, 2001 (10022001) is the most recent palindromic date before 01/02/2010.

Continuing backwards, 2000 gives us an invalid month (00) so that year is out. All of the 1900s are out because they imply an invalid day of month (91). Ditto the 1800s, 1700, 1600s, 1500s and 1400s. Finally, we come to the 1300s, which implies a valid day of month (31). 1399 through 1391 again give invalid months but 1390 gives us a a valid month (09) and a valid day of month (31). Alas, although September 31, 1390 (09311390) is palindromic, September has only 30 days! Back to the drawing board…1389 through 1381 yield invalid month numbers but 1380 gives us a valid month (08) and a valid day of month (31). Let’s see – that would be August 31, 1380 (08311380). Yup, that’s a palindrome and a valid date. That’s our second answer.

So the most recent palindromic date before January 2, 2010 occurred less than ten years ago.