# How many times in the future after the 1st of January of 2019 will a palindrome date happen?

I'm trying to solve the following problem:

How many times in the future (before the year 10000) will after the 1st January of 2019 happen a palindrome date. Date is in the dx-my-ymxd forum, and we suggest that $$dx\in\{01,...,31\}$$.

Could you help me with how to solve this issue? I don't know how to start. Thank you.

• How many day/month combinations are there? How many give a year greater than 2019 when the numbers are reversed? Example: 6 October gives 06-10-0160 which does not qualify. Oct 6, 2019 at 13:15
• Just a few days ago, we had 02/02/2020. Feb 6, 2020 at 6:07

The following MiniZinc model arrives at $$269$$ dates:

var 0..3: d;  % 1st digit of day
var 0..1: m;  % 1st digit of month
var 0..9: x;  % 2nd digit of day
var 0..9: y;  % 1st digit of year
var bool: leapYear;
var 2019..9999: year;

%  day must be in 01..31
constraint (d + x) > 0;

constraint (d*10+x) <= 31;

%  month must be in 01..12
constraint (m + y) > 0;

constraint (10*m + y) <= 12;

%  2019 or later
constraint (1000*y + 100*m + 10*x + d) == year;
constraint 2019 <= year;

%  certain months have less than 31 days
constraint ((d*10+x) <= 30) \/ ((10*m+y) in {1,3,5,7,8,10,12});

%  February has 28 days in normal years and 29 in leap years
constraint leapYear == (((year mod 4) == 0) /\
(((year mod 100) != 0) \/ ((year mod 400) == 0)));
constraint ((10*m+y) != 2) \/
((d*10+x) < 29) \/
(((d*10+x) == 29) /\ leapYear);

output ["\(d)\(x)-\(m)\(y)-\(y)\(m)\(x)\(d)"]


The number of $$269$$ dates is confirmed by the following C# code:

DateTime dt = new DateTime(2019, 1, 1);
DateTime lastDay = new DateTime(9999, 12, 31);
int count = 0;

for(; dt < lastDay; dt = dt.AddDays(1))
{
string s = dt.ToString("ddMMyyyy");
bool palindrome = true;

for (int i = 0; i < s.Length/2; i++)
{
if (s[i] != s[s.Length - i - 1])
{
palindrome = false;
break;
}
}

if (palindrome)
{
count++;
}
}

Console.WriteLine(count);

• My count is $269$ I believe your count includes invalid dates 31/04/4013, 31/06/6013, and 31/09/9013. Oct 6, 2019 at 23:02
• Yes, I have no constraints which prevent invalid day numbers which do not fit for the respective month. I'll extend my model. Oct 7, 2019 at 10:34

To develop Daniel Mathias comment into a way to obtain the same answer as Axel Kemper without a computer:

For each possible value of day and month digit, reversing these gives a year from 2019 onwards except for

• all dates in January, October or November (92 total)
• dates in February ending 0 or 1 (5 total: 01,10,11,20,21)

Thus each valid day-month combination except these gives one valid palindromic date except possibly

• 29th Feb, where we also need it to be a leap year. However, reversing gives 29-02-2092, and 2092 is a leap year.

So the answer is $$366-92-5=269$$.

• @Toby Mak $2092=4\times 523$. Oct 7, 2019 at 11:12
• Whoops, my bad. Oct 7, 2019 at 11:13
• Cool! Pencil and paper can be far better than a computer. Oct 7, 2019 at 11:54