*** Welcome to piglix ***

Kaprekar's routine


Kaprekar's routine is an algorithm in recreational mathematics devised by the Indian mathematician D. R. Kaprekar which produces a sequence of numbers which either converges to a constant value or results in a repeating cycle. The algorithm is as follows:

For example, if we start with 3524 then we get:

A sequence like this is sometimes called a Kaprekar sequence and the function K(n) = n′n″ is the Kaprekar mapping.

Some numbers map to themselves: for instance if n = 0, then 0 − 0 = 0; if n = 495, then 954 − 459 = 495; if n = 6174, then 7641 − 1467 = 6174. These are the fixed points of the Kaprekar mapping. If the sequence reaches one of these numbers, it will repeat indefinitely.

All Kaprekar sequences will either reach one of these fixed points or will result in a repeating cycle. Either way, the end result is reached in a fairly small number of steps.

Note that the numbers n′ and n″ have the same digit sum and hence the same remainder modulo 9 (if we are using base 10). Therefore, each number in a Kaprekar sequence of base 10 numbers (other than possibly the first) is a multiple of 9. In the general case of base b, the numbers in the sequences will be multiples of b − 1.

In 1949 D. R. Kaprekar discovered that if the above process is applied to base 10 numbers of 4 digits, the resulting sequence will almost always converge to the value 6174 in at most 8 iterations, except for a small set of initial numbers which converge instead to 0. The number 6174 is sometimes known as Kaprekar's constant.

The set of numbers that converge to zero depends on whether leading zeros are discarded (the usual formulation) or are retained (as in Kaprekar's original formulation).

In the usual formulation, there are 77 four-digit numbers that converge to zero, for example 2111. However, in Kaprekar's original formulation the leading zeros are retained, and only repdigits such as 1111 or 2222 map to zero. This contrast is illustrated below:


...
Wikipedia

...