Kaprekar's constant

Kaprekar's constant is equal to 6,174, named after discoverer D. R. Kaprekar.Kaprekar Routine from Wolfram MathWorld
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 1,111, then repeated application of the \(K\) will eventually reach the fixed point 6,174 within seven steps.
For example, if we start with any anagram of 1,447:
:7,441 - 1,447 = 5,994
:9,954 - 4,599 = 5,355
:5,553 - 3,555 = 1,998
:9,981 - 1,899 = 8,082
:8,820 - 288 = 8,532
:8,532 - 2,358 = 6,174
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.
== Trivia ==
*The number 495 is also the number of in a double-nine set.
*The number 6,174 is also the sum of the first three powers of 18 (excluding 1).
== Sources ==
Category:Numbers
Category:Class 1
Category:Even numbers
Category:Non-powers
Category:Numbers with 4 to 6 digits