[Math] $9$ divides $n-r(n)$ where $r(n)$ is $n$ with its digits reversed

divisibilityelementary-number-theory

I see in many Brazilian sites that, if you get a number and subtract it by its reverse, you will have zero or a multiple of nine. For example:

22 - 22 = 0
51 - 15 = 36 (multiple of 9)
444 - 444 = 0
998 - 899 = 99 (multiple of 9)
1350 - 0531 = 819 (multiple of 9)
654321 - 123456 = 530865 (multiple of 9)

I wrote this Python code to test a range of numbers:

import math

for i in range(1, 1000001):
    inverse = int(str(i)[::-1])
    result = int(math.fabs(i - inverse))

    if result != 0 and result % 9 != 0 :
        print(result)

for that range it seems to be true. But I wasn't able to find any similiar type of "mathematical curiosity" in English language sites.

If it is true, is there explanation to that? Because the sites that spread that information, does not provide any explanation.

Best Answer

Sure, there is an explanation for this! In fact, this is not only true for when you reverse the digits of a number but for any permutation of its digits!

For any integer $n$, let $q(n)$ be the sum of its digits. It is a fact that $q(n) \equiv n \mod 9$. Let $n'$ be the number $n$ with its digits reversed. (Or, for the more general case I mentioned above, ANY number resulting in permuting the digits of $n$.) Then $q(n) = q(n')$, since the digits are the same, just reordered. So $q(n) \equiv q(n') \mod 9$ and therefore $q(n) - q(n') \equiv n - n' \equiv 0 \mod 9$, or in other words, $n - n'$ is divisible by 9.