This post is part of a series on Mohammad Anwar’s excellent Weekly Challenge, where hackers submit solutions in Perl, Raku, or any other language, to two different challenges every week. (It’s a lot of fun, if you’re into that sort of thing.)
Task #2 this week asks us to (and I quote): print all Palindrome Dates between 2000 and 2999. The format of date is mmddyyyy. For example, the first one was on October 2, 2001 as it is represented as 10022001.
It’s pretty easy to avoid using any sort of date library with a couple of key observations about the problem domain. First, we’ll split it up into month (mm
), day (dd
), century (cc
), and 2-digit year (yy
). Thus our “baseline” date format is mm dd cc yy
.
If we use R[xx]
as shorthand for “string reverse of xx“, we can rewrite the date in a couple of different ways:
mm dd cc yy # Original
R[yy] R[cc] cc yy # Start with year
mm dd R[dd] R[mm] # Start with mm/dd
R[yy] dd R[dd] yy # Start with yy and dd