Take a 4-digit number whose digits are not all the same; in other words, a 4-digit number besides 1111, 2222, … 9999. Rearrange the digits first in ascending order and then in descending order to get two numbers. Subtract the smaller from the larger and then repeat the process.

For example, take 4050 and rearrange them as above to get 0045 and 5400 respectively. Now,`5400 - 0045 = 5355`

5553 - 3555 = 1998 (rearranging the result above, 5355)

9981 - 1899 = 8082

8820 - 0288 = 8532

8532 - 2358 = 6174

7641 - 1467 = 6174 (starts recurring)

For 1011,`1110 - 0111 = 0999`

9990 - 0999 = 8991

9981 - 1899 = 8082

8820 - 0288 = 8532

8532 - 2358 = 6174

7641 - 1467 = 6174 (starts recurring)

In other words, the result is that you always end up with the very mysterious 6174. The mathematician who discovered this curious property in 1949 was Dattathreya Ramchandra Kaprekar or D. R. Kaprekar, a school teacher from Maharashtra with a passion for number theory. 6174 is therefore also known as Kaprekar's Constant and this process is known as Kaprekar's Routine.