Problem 6 · Quasi-palindromic numbers
Counting via disjoint cases around four-digit palindromes.
Integer answer, at most 4 digitsWe call a number quasi-palindromic if adding 1 to one and only one of its digits, leaving the others unchanged, produces a palindrome. How many four-digit quasi-palindromic numbers are there?
Reasoned solution
Key idea: a four-digit palindrome $\overline{abba}$ requires two equalities: equal outer digits and equal middle digits. Adding 1 to a single digit can only “fix” one of the two equalities; the other must already hold.
Let the number be $\overline{d_1 d_2 d_3 d_4}$. There are four cases depending on which digit we increment (that digit must be $\le 8$ so there is no carry):
Case 1 — increment $d_2$: we need $d_1 = d_4$ and $d_3 = d_2+1$. Choices: $d_1=d_4 \in \{1,\dots,9\}$ and $d_2 \in \{0,\dots,8\}$ → $9 \cdot 9 = 81$.
Case 2 — increment $d_3$: we need $d_1 = d_4$ and $d_2 = d_3+1$ → also $9 \cdot 9 = 81$.
Case 3 — increment $d_1$: we need $d_2 = d_3$ and $d_4 = d_1+1$. Choices: $d_1 \in \{1,\dots,8\}$ and $d_2=d_3 \in \{0,\dots,9\}$ → $8 \cdot 10 = 80$.
Case 4 — increment $d_4$: we need $d_2 = d_3$ and $d_1 = d_4+1$. Choices: $d_4 \in \{0,\dots,8\}$ and $d_2=d_3 \in \{0,\dots,9\}$ → $9 \cdot 10 = 90$.
The four cases are pairwise disjoint: their conditions contradict each other (for instance, $d_3 = d_2+1$ is incompatible with $d_2 = d_3+1$ and with $d_2=d_3$; and $d_1=d_4$ is incompatible with $d_4 = d_1+1$). Hence no number is counted twice.