Dattatreya Ramchandra Kaprekar (1905-1986) was an Indian mathematician.
In the 1940's, he discovered an intriguing property of the number 6174 (now callled the Kaprekar constant).
We start by choosing a 4 digit number (the fewer the repeated digits, the better).
We then arrange the digits to make
1) the biggest number we can and then rearrange the digits to make
2) the smallest number.
For example, let's start with 6758.
1) We make the largest number we can by rearranging the digits making 8765.
2) We rearrange those digits to make the smallest number 5678.
Subtracting the second number from the first we get
8765 - 5678 = 3087
With 3087, we repeat the steps we just followed:
8730 - 0378 = 8352
Continuing with 8352
8532 - 2358 = 6174
We see that it took just three steps to reach 6174 and after that the sequence just keeps repeating.
Kaprekar stated that when any 4 digit number undergoes the "Kaprekar algorithm", seven will be the maximum number of steps and the final number will be 6174.