> [!abstract]
> 6174 is known as Kaprekar's constant after the Indian mathematician D. R. Kaprekar. This number is renowned for the following rule:
> 1. Take any four-digit number, using at least two different digits (leading zeros are allowed).
> 2. Arrange the digits in descending and then in ascending order to get two four-digit numbers, adding leading zeros if necessary.
> 3. Subtract the smaller number from the bigger number.
> 4. Go back to step 2 and repeat.
> The above process, known as Kaprekar's routine, will always reach its fixed point, 6174, in at most 7 iterations. Once 6174 is reached, the process will continue yielding 6174.
### Example
---
Let's pick 1549 as an example. Sort its digits in descending and descending order, and subtract the smaller number from the bigger number, then repeat until Kaprekar's constant is reached:
$ \begin{flalign} 9541 - 1459 = 8082 && \end{flalign} $
$ \begin{flalign} 8820 - 0288 = 8532 && \end{flalign} $
$ \begin{flalign} 8532 – 2358 = 6174 && \end{flalign} $
Check that the process will continue yielding Kaprekar's constant:
$ \begin{flalign} 7641 – 1467 = 6174 && \end{flalign} $
> [!note]
> It's a fun little recreational math trivia, but there's nothing unique about Kaprekar's constant. There is an infinite number of arbitrary procedures (such as "sort the digits in descending and ascending numbers, and subtract them") that also yield a fixed point, such as in other number bases, using modulo operations, cyclical fixed points, etc. Kaprekar's constant is just well known because it's very simple and guarantees convergence to a relatively small number.