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

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.


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.


Hint $\ $ An integer is congruent to its digit sum mod $9$ (casting nines). The digit sum of the reversed number is the same as the original, so their difference is zero mod $\,9.\,$ More precisely

$${\rm mod}\ 9\!:\,\ n = P(10)\equiv \overbrace{P(1)= \bar P(1)}^{\rm digit\ sum}\equiv \bar P(10)= \bar n\,\ \Rightarrow\,\ 9\mid n-\bar n\qquad $$

where $\,P(10) = d_n 10^n+\cdots + d_1 10 + d_0$ is the radix polynomial, therefore $\,P(1) = $ digit sum, and $\bar n$ = the reversal of $\,n,\,$ and $\,\bar P\,$ is the reversed (reciprocal) polynomial. Therefore the congruence $\,P(10)\equiv P(1) = $ digit sum, the key idea behind casting out nines, is nothing but a special case of the Polynomial Congruence Rule, a consequence of the polynomial form of radix representation.

The above implies that the result holds true more generally if instead of reversing the digits we choose any integer with the same (unordered) list of digits, since this has the same digit sum, e.g. we can arbitrarily permute the digits, insert zero digits, etc.