The Kaprekar routine is an algorithm for rearranging and subtracting digits, introduced for four-digit
numbers by D. R. Kaprekar (Deutsch and Goldman 2004) and generalizable
to -digit numbers. To apply the Kaprekar routine to a number
, arrange the digits in descending
(
) and ascending (
) order. Now compute
(discarding any initial 0s) and iterate, where
is sometimes called the Kaprekar
function. The algorithm reaches 0 (a degenerate case),
a constant, or a cycle, depending on the number of digits
and the starting value
. The list of values is sometimes
called a Kaprekar sequence, and the result
is sometimes called a Kaprekar number (Deutsch and Goldman
2004), though this nomenclature should be deprecated because of confusion with the
distinct sort of Kaprekar number.
In any integer base , the two rearrangements have the same digit
sum and are congruent to it modulo
. Their difference is therefore divisible
by
, so every output in decimal
notation is divisible by 9.
In decimal notation, the nonzero fixed points
satisfying
are given by 495, 6174, 549945, 631764, ... (OEIS A099009).
Similarly, the numbers
lying on cycles of the map
with length
are given by 53955, 59994, 61974, 62964, 63954, 71973,
... (OEIS A099010).
Iterating the Kaprekar map in decimal notation, all one- and two-digit numbers give 0. Exactly 60 three-digit
numbers, namely 100, 101, 110, 111, 112, 121, 122, 211, 212, 221, ... (OEIS A090429),
reach 0, while the rest give 495 in at most 5 iterations.
Exactly 77 four-digit numbers, namely 1000, 1011, 1101,
1110, 1111, 1112, 1121, 1211, ... (OEIS A069746),
reach 0, while the remainder give 6174 in at most 7 iterations.
The value 6174 is sometimes known as Kaprekar's
constant (Deutsch and Goldman 2004). For five-digit
numbers, the nonzero outcomes are three cycles of lengths 2, 4, and 4, as listed
below. Iterations are counted as applications of the
map , without counting the initial number.
If leading 0s are retained so that each iteration uses the same number of digits, the outcome can change. For
example, dropping leading 0s gives , while retaining
three digits gives
.
For four decimal digits, all starting values whose digits are not all equal reach 6174 in at most 7 iterations, while the values with four identical digits reach 0 (Nishiyama 2006). Numberphile (2011) illustrates the four-digit routine.
The following table lists nonzero cycles in various bases , with 0 shown when the zero cycle is the only outcome.
The columns start with
digits, and all cycle values are
written in decimal notation.
| possible cycles for | |
| 2 | 0,
0, 9, 21, |
| 3 | 0, 0, (32, 52), 184, (320, 580, 484), ... |
| 4 | 0, 30, |
| 5 | 8, (48, 72), 392, (1992, 2616, 2856, 2232), (7488, 10712, 9992, 13736, 11432), ... |
| 6 | 0, 105, (430, 890, 920, 675, 860, 705), |
| 7 | 0, (144, 192), (1068, 1752, 1836), (9936, 15072, 13680, 13008, 10608), (55500, 89112, 91800, 72012, 91212, 77388), ... |
| 8 | 21, 252, |
| 9 | (16, 48), (320, 400), |
| 10 | 0, 495, 6174, |
The figure above (similar to that appearing on the cover of the above issue of The Mathematics Teacher) shows the number of steps required for the Kaprekar routine
to reach a fixed point for values of to 9999, partitioned into rows of length 100 (Deutsch and
Goldman 2004). In this plot, numbers having fewer than four digits
are padded with leading 0s. The ten values with four identical digits
reach 0, while all other values reach 6174.