Number of "swappy" numbers?

434 Views Asked by At

A number is called swappy if it is not a palindrome, but swapping two of its digits produces a six-digit palindrome. For example, the number $813381$ is swappy, because we can swap the last two digits to get $813318$, which is a palindrome.

How many swappy six-digit numbers are there?

What I did was find all 6-digit palindromes, which would be $9\cdot10\cdot10$, which is $900$. From there, I used $\binom{6}{2}$ to find all selections of 2 numbers, which turns out to be $15$. How do I eliminate all the over counts going from here?

1

There are 1 best solutions below

0
On

The three places where the count $900 \cdot \binom{6}{2}$ is wrong are:

  • You should not be considering starting with a palindrome and swapping positions $(1,6)$, $(2,5)$, or $(3,4)$. That leaves you with the number you started, and a swappy number cannot be a palindrome.
  • You don't need to consider swapping positions $(1,2), (1,3), (1,4), (1,5), (2,3), (2,4)$. Their mirror images $(5,6), (4,6), (3,6), (2,6), (4,5), (3,5)$ will do just as well, and this way you avoid double-counting. Each swappy number becomes a palindrome in exactly two ways: if a swap yields a palindrome, so does the mirror image of that swap. The exception is numbers like $102210$, where the $(1,2)$ swap yields $012210$, which is bad, but the $(5,6)$ swap is okay - so we deal with those here as well.
  • There are fewer than $900$ possibilities for the digits of the palindrome you started with, because the two digits you're swapping must be different.

Once you fix these three things, you'll have the right answer.