Source

I got this problem from Rustan Leino, who got this problem from Olean Brown, who had pointed me to the following web page that claims to read your mind.

I solved it and wrote up my solution.

Problem

Think of a positive integer; call it $X$. Shuffle the decimal digits of $X;$ call the resulting number $Y.$ Subtract the smaller of $X$ and $Y$ from the larger; call the difference $D.$ $D$ has the following property: Any non-zero decimal digit of $D$ can be determined from the remaining digits. That is, if you ask someone to hide any one of the non-zero digits in the decimal representation of $D,$ then you can try to impress the other person by figuring out the hidden digit from the remaining digits. How can you do this? Why does it work?

Solution
Reveal

Add up the remaining digits modulo 9; call the result $A$. Guess $9 - A$.

First, observe that for any natural number $n$, the sum of its digits is congruent to $n$ modulo 9. The reason is that for each digit $d$ of $n$, it contributes $d$ to the sum of digits and $d \cdot 10^i$ to $n$ itself, where $i$ corresponds to the position of the digit. So it contributes $d(10^i - 1)$ to the difference between the sum of digits of $n$ and $n$. This contribution equals $d(10-1)\sum_{j=0}^{i-1} 10^j$, which has $10 - 1 = 9$ as a factor. Since all contributions to the difference between the sum of digits of $n$ and $n$ have 9 as a factor, this difference is a multiple of 9.

Since $X$ and $Y$ have the same digits, they have the same sum of digits. Each of them is congruent modulo 9 to its sum of digits, so they're congruent modulo 9 to each other. So, subtracting them gives a number congruent to 0 modulo 9. This means $D$ is congruent to 0 modulo 9.

Thus, the sum of the digits of $D$ is congruent, modulo 9, to 0. This means that if you take one digit $d$ away, the resulting sum of digits will be congruent to $-d$ modulo 9. This means $A$ will be congruent to $-d$ modulo 9. Since $d \neq 0$, you can calculate $d$ as $9 - A$.