Take a four-digit number whose digits are not all the same, rearrange its digits into the largest and the smallest numbers they can make, and subtract. Then do the same with the answer, and again with the next answer. Every allowed start arrives at within seven rounds and stays there. This page states the rules exactly, shows why never moves, explains why so many routes merge after a single round, and says where the number seven comes from.
Key terms
Kaprekar’s constant
Definition Kaprekar’s constant is the number , named after the Indian mathematician D. R. Kaprekar, who devised the routine that leads to it in 1949. The routine works in base ten with exactly four digit places. Write the number with four digits, adding leading zeros if needed, so that becomes . Arrange the four digits in decreasing order to get the largest number they can make and in increasing order to get the smallest, and subtract the smallest from the largest. Write the result with four digits and repeat. The theorem says that every start from to whose four digits are not all equal reaches after at most seven subtractions, and that from then on every subtraction gives again. The ten starts with four equal digits, such as , are excluded, because both arrangements are the same number and the routine falls to and stays there. The theorem is proved by checking all allowed starts, which is possible because there are only finitely many. Seven is the longest route, and most starts need fewer rounds.
In plain words Each round keeps only how far apart the digits are and forgets their order. That leaves so few possible results that every allowed route funnels into within seven rounds, and rebuilds itself.
Example The start needs all seven rounds. Its digits in decreasing order make and in increasing order , and the rounds are
The next round gives again. Counting the subtractions needed by each of the allowed starts gives the table below, in which the one start that needs none is itself.
| Subtractions needed | Allowed starts |
|---|---|
Kaprekar’s routine
Definition Kaprekar’s routine on four digits is the rule that sends a number from to , written with four digit places, to the largest arrangement of its four digits minus the smallest arrangement, again written with four places. Suppose the digits of in decreasing order are . The largest arrangement has in the thousands place and in the units place, the smallest has them the other way round, and and trade the hundreds and tens places. So
The result depends only on the outer gap and the inner gap . When the digits are not all equal, the outer gap is a whole number from to and the inner gap is a whole number from up to the outer gap, which gives possible pairs of gaps. Different pairs give different results, so after one round every allowed start has become one of just numbers.
In plain words The routine forgets the order of the digits and even most of the digits themselves. Only two gaps survive a round, so starts with the same two gaps land on the same number.
Example The numbers and are not rearrangements of each other, but both have outer gap and inner gap . The formula gives for both, and the subtractions agree,
From there both routes continue through and , three rounds each.
Fixed point
Definition A fixed point of a rule , which sends each allowed input to an output, is an input with . When a value is fed back into the rule over and over, reaching a fixed point means that every later round returns the same value. A fixed point does not by itself say which starts lead to it. That has to be shown separately, and some repeated rules never settle at a fixed point and run around a loop instead.
In plain words A fixed point is a value the rule leaves unchanged. Landing on one ends the route, because every later round gives it back.
Example The digits of in decreasing order make and in increasing order , and
so . The gap formula shows the same thing, since has outer gap and inner gap , and . A check of all inputs from to finds exactly one other fixed point, , and the routine reaches it only from the ten excluded starts with four equal digits.
Leading zero
Definition A leading zero is a written in front of the first nonzero digit of a number so that the number fills a fixed number of digit places. It does not change the value, since and are the same number, but it does change the list of digits, and that list is what Kaprekar’s routine sorts. The routine always uses four places, so counts as the digits , , and , and counts as , , and . A zero digit sorts like any other digit, so it stands at the front of the smallest arrangement, as gives . The gap formula is less than only when and , so for an allowed start the only result that begins with a zero is .
In plain words Always keep four slots, even when some of them hold zeros. The zeros are digits too, and sorting them is part of the rule.
Example Start from . The first round gives . Keeping four places, the next rounds give
five rounds in all. If the zero of is dropped, the digits are , and , both arrangements are , and the routine falls to and stays there. That is a different procedure with three places, not a failure of the theorem.
Check yourself
- Change the number of places to three. Start from , and in each round subtract the smallest arrangement of the three digits from the largest, keeping three places. Where does the route end?
Show the answer
The rounds are
and the next round gives again. So is a fixed point, and the route ends there after four rounds. With three digits the middle digit cancels, as in the 1089 trick, and each round gives . Checking all three-place starts whose digits are not all equal shows that every one of them reaches within six rounds.
- Start from the number . Follow the four-place routine to and count the rounds. What goes wrong if is treated as a one-digit number?
Show the answer
With four places the start is , whose digits are not all equal, so it is allowed. The rounds are
six rounds in all. As a one-digit number, has only one arrangement, so the subtraction gives , and the routine stays at . The three leading zeros are what make an allowed start.
- Change the number of places to two. Start from and keep two places, so that is written . Does the route reach a fixed point?
Show the answer
No. The rounds are , then , then , then , then , and then returns to a value already seen. From there the route runs around the loop
forever. With two digits each round gives , one of the nine numbers , , , , , , , and . These go to , , , , , , , and , so none of them is sent to itself. The two-digit routine has no fixed point apart from , and every start with two different digits ends up in this loop of five numbers. A single destination is therefore not guaranteed. Four places and three places happen to have one, and two places do not.