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

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.

• Note that zero is also a multiple of nine. Commented Feb 27, 2015 at 22:18
• If your number has an odd number of digits, you can prove that the resulting difference will be divisible by $99$. Commented Feb 28, 2015 at 3:41

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 out nines). The digit sum of the reversed number (or any permuted digits) is the same as the original, so their difference is zero mod $$\,9,\,$$ i.e. if $$\,n = P(10) = d_k 10^k+\cdots + d_1 10 + d_0$$ is its radix $$\rm\color{#0a0}{polynomial}$$, then $$P(1)\:\!$$ is its digit sum, and $$\bar n$$ = digit reversal of $$\,n,\,$$ and $$\,\bar P\,$$ is the reversed (reciprocal) polynomial, then

$$\ \ {\rm mod}\ 9\!:\,\ \color{#0af}{10}\equiv \color{#c00}1\,\Rightarrow\, n = P(\color{#0af}{10})\equiv \underbrace{P(\color{#c00}1)= \bar P(\color{#c00}1)}_{\rm equal\ digit\ sum}\equiv \bar P(\color{#0af}{10})= \bar n\,\ \Rightarrow\,\ 9\mid n-\bar n\qquad\quad$$

Notice that the congruence $$\,P(\color{#0af}{10})\equiv P(\color{#c00}1) =$$ digit sum, the key idea behind casting out nines, is nothing but a special case of the $$\rm\color{#0a0}{Polynomial}$$ Congruence Rule, which applies here due to the $$\rm\color{#0a0}{polynomial}$$ form of radix representation.

Thus the above implies that the result holds true more generally if instead of reversing the digits we choose any digit permutation, i.e. 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.

Let the number be: $\overline{a_1a_2a_3...a_n}$ since we're using decimal positioning system we can write it as:

$$\overline{a_1a_2a_3...a_n} = 10^{n-1}a_1 + 10^{n-2}a_2 + ... + a_n$$

While if we flip the digits, then we'll have a number:

$$\overline{a_na_{n-1}a_{n-2}...a_1}=10^{n-1}a_n + 10^{n-2}a_{n-1} + ... + a_1$$

Now since $10 \equiv 1 \pmod 9$, by taking powers of both sides we have: $10^k \equiv 1 \pmod 9 \forall k \in \mathbb{N}$ So we have:

$$10^{n-1}a_1 + 10^{n-2}a_2 + ... + a_n \equiv a_1 + a_2 + ... + a_n \pmod 9$$

On the other side,simularly :

$$10^{n-1}a_n + 10^{n-2}a_{n-1} + ... + a_1 \equiv a_n + a_2 + ... + a_1 \pmod 9$$

Subtract them and you have:

$$10^{n-1}a_1 + 10^{n-2}a_2 + ... + a_n - (10^{n-1}a_n + 10^{n-2}a_{n-1} + ... + a_1) \equiv a_1 + a_2 + ... + a_n - (a_n + a_2 + ... + a_1) \equiv 0 \pmod 9$$

From this we have that:

$$9\mid 10^{n-1}a_1 + 10^{n-2}a_2 + ... + a_n - (10^{n-1}a_n + 10^{n-2}a_{n-1} + ... + a_1)$$ $$\implies 9 \mid \overline{a_1a_2a_3...a_n} - \overline{a_na_{n-1}a_{n-2}...a_1}$$

Hence the proof.