What is the Kaprekar constant?

6174 – Wikipedia

The Kaprekar constant originates from number theory and is a natural number that arises as a fixed point through a certain iterative algorithm. It is named after the Indian mathematician D. R. Kaprekar (1905-1986), who first described this property of numbers for four-digit numbers in 1949.

Kaprekar showed that for four-digit decimal numbers with at least two different digits, the number 6174 is obtained after no more than seven repetitions of the method.

Algorithm for calculation – Kaprekar’s routine

To calculate the Kaprekar constant of a three-, four-, six-, eight-, nine- or ten-digit decimal number in which not all digits may be the same, the digits are ordered once to produce the largest possible number (a) and then (with leading zeros if necessary) to produce the smallest possible number (b). Then form the difference d=a-b and apply the procedure to the result d again.

At some point, the process leads to a cycle, and if this has a length of one, i.e. a number x is constantly repeated, x is called a Kaprekar constant.