Kaprekar's constant is equal to 6174, named after discoverer D. R. Kaprekar.
The number arises in analysis of the following function: given a four-digit positive integer \(n\), let \(a\) be the number formed by sorting \(n\)'s digits in ascending order, and let \(d\) be the number formed by sorting the digits in descending order (adding trailing zeroes so that \(d\) has 4 digits). We now define \(K(n) = d - a\). Kaprekar has shown that, if we start with any 4-digit number other than a multiple of 1111, then repeated application of the \(K\) will eventually reach the fixed point 6174 within seven steps.
For example, if we start with any anagram of 1447:
- 7441 - 1447 = 5994
- 9954 - 4599 = 5355
- 5553 - 3555 = 1998
- 9981 - 1899 = 8082
- 8820 - 0288 = 8532
- 8532 - 2358 = 6174
Similar situations happen for other numbers of digits, but not as cleanly. With three digits, the fixed point 495 occurs within six steps, but there are 60 exceptions that result in 0. With five digits, the process eventually gets stuck in one of three periodic loops, and similar behavior happens for more digits.