Non-trivial "I know what number you're thinking of"

I have a "magic trick" I like to perform for classes on a random day throughout the semester (I cannot take credit for its creation! I do not know the original source...).

"Magic" trick:

  1. Pick a four digit number with at least two distinct digits (four is completely arbitrary).

  2. Rearrange this number any way you like, swapping at least one pair of digits (it can be any non-identity permutation).

  3. Subtract the smaller of these two numbers from the larger, the original and mixed-up. For example, if you pick $3572$ as your number and mix it up to form $7235$, you'll subtract $7325 - 3572 = 3753$. (It actually doesn't need to be $\text{larger} - \text{smaller}$, but negatives confuse the class, even though they don't matter mathematically)

  4. Now take the result of the subtraction, and keep one of its nonzero digits a secret. Tell me the other digits in any order you like. (I tell the class that picking $0$ is "too boring!" After reading and seeing how this trick works, think about why I won't let them pick $0$.)

I will know your secret digit by the time you've told me your last digit. How can I possibly do that?

"Magic" Revealed:

Recall that the sum of digits of a number $n$ (the "digital root") is the remainder upon division of $n$ by $9$. But clearly any permutation of the digits doesn't affect this sum, so our original number $n$ and our mixed up number $n'$ have the same digital root, so that $n - n' \equiv 0 \pmod 9$. Thus, having told our participant to keep any nonzero digit to themselves, their secret digit must be whatever it takes to make the sum of digits $0 \bmod 9$. For example, suppose I'm given the digits $3, 3,$ and $7$ (perhaps the participant chose $7325 - 3572$ as their difference). Their sum is $3 + 3 + 7 \equiv 4 \pmod 9$, and they must have been keeping $5$ to themselves, since $4 + 5 \equiv 0 \pmod 9$.

It's certainly not the deepest mathematics involved, but I consider it nontrivial -- and quite fun!


Kaprekar's constant

Start with any number of up to $4$ digits, with at least two different digits: add leading $0$'s if necessary to make $4$ digits. Write the digits in decreasing order and in increasing order, and subtract the second from the first. Repeat $7$ times. The result will be $6174$.

For example: start with $1234$

$4321 - 1234 = 3087$

$8730 - 0378 = 8352$

$8532 - 2358 = 6174$

$7641 - 1467 = 6174$ (4 times)

EDIT: You might also look at some of the answers to this MathOverflow question.


Pick any integer number between 100 and 999. Write it again next to the number, and now you have a 6 digits number. Divide it by 7, divide it by 11, divide it by 13. In no step there should be any remainder (you can simulate that you're guessing or thinking very hard about them). The end result is the number chosen initially.

For example for 439:

439439 (write it again, next to the number)

439439 / 7 = 62777

62777 / 11 = 5707

5707 / 13 = 439

Why does this work? Because 7 x 11 x 13 = 1001