Video 3, chapter 2

Kaprekar's Constant and the Road to 6174

How Kaprekar's routine, the largest arrangement of four digits minus the smallest, brings every four-digit start with at least two different digits to Kaprekar's constant 6174, a fixed point, when leading zeros are kept.

  • Video 3, chapter 2
  • Numbers with a hidden mechanism

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 61746174 within seven rounds and stays there. This page states the rules exactly, shows why 61746174 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 61746174, 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 55 becomes 00050005. 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 00000000 to 99999999 whose four digits are not all equal reaches 61746174 after at most seven subtractions, and that from then on every subtraction gives 61746174 again. The ten starts with four equal digits, such as 77777777, are excluded, because both arrangements are the same number and the routine falls to 00000000 and stays there. The theorem is proved by checking all 99909990 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 61746174 within seven rounds, and 61746174 rebuilds itself.

Example The start 10041004 needs all seven rounds. Its digits in decreasing order make 41004100 and in increasing order 00140014, and the rounds are

4100−0014=4086,8640−0468=8172,8721−1278=7443,7443−3447=3996,9963−3699=6264,6642−2466=4176,7641−1467=6174.\begin{aligned} 4100 - 0014 &= 4086, \\[0.4em] 8640 - 0468 &= 8172, \\[0.4em] 8721 - 1278 &= 7443, \\[0.4em] 7443 - 3447 &= 3996, \\[0.4em] 9963 - 3699 &= 6264, \\[0.4em] 6642 - 2466 &= 4176, \\[0.4em] 7641 - 1467 &= 6174. \end{aligned}

The next round gives 7641−1467=61747641 - 1467 = 6174 again. Counting the subtractions needed by each of the 99909990 allowed starts gives the table below, in which the one start that needs none is 61746174 itself.

Subtractions neededAllowed starts
0011
11383383
22576576
3324002400
4412721272
5515181518
6616561656
7721842184

Kaprekar’s routine

Definition Kaprekar’s routine on four digits is the rule KK that sends a number nn from 00 to 99999999, 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 nn in decreasing order are a≥b≥c≥da \ge b \ge c \ge d. The largest arrangement has aa in the thousands place and dd in the units place, the smallest has them the other way round, and bb and cc trade the hundreds and tens places. So

K(n)=999a+90b−90c−999d=999(a−d)+90(b−c).\begin{aligned} K(n) &= 999a + 90b \\[0.4em] &\quad - 90c - 999d \\[0.4em] &= 999(a - d) \\[0.4em] &\quad + 90(b - c). \end{aligned}

The result depends only on the outer gap a−da - d and the inner gap b−cb - c. When the digits are not all equal, the outer gap is a whole number from 11 to 99 and the inner gap is a whole number from 00 up to the outer gap, which gives 5454 possible pairs of gaps. Different pairs give different results, so after one round every allowed start has become one of just 5454 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 98719871 and 87608760 are not rearrangements of each other, but both have outer gap 88 and inner gap 11. The formula gives 999⋅8+90⋅1=8082999 \cdot 8 + 90 \cdot 1 = 8082 for both, and the subtractions agree,

9871−1789=8082,8760−0678=8082.\begin{aligned} 9871 - 1789 &= 8082, \\[0.4em] 8760 - 0678 &= 8082. \end{aligned}

From there both routes continue through 8820−0288=85328820 - 0288 = 8532 and 8532−2358=61748532 - 2358 = 6174, three rounds each.

Fixed point

Definition A fixed point of a rule ff, which sends each allowed input to an output, is an input xx with f(x)=xf(x) = x. 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 61746174 in decreasing order make 76417641 and in increasing order 14671467, and

7641−1467=6174,7641 - 1467 = 6174,

so K(6174)=6174K(6174) = 6174. The gap formula shows the same thing, since 61746174 has outer gap 7−1=67 - 1 = 6 and inner gap 6−4=26 - 4 = 2, and 999⋅6+90⋅2=6174999 \cdot 6 + 90 \cdot 2 = 6174. A check of all 1000010000 inputs from 00000000 to 99999999 finds exactly one other fixed point, 00000000, and the routine reaches it only from the ten excluded starts with four equal digits.

Leading zero

Definition A leading zero is a 00 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 09990999 and 999999 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 999999 counts as the digits 00, 99, 99 and 99, and 55 counts as 00, 00, 00 and 55. A zero digit sorts like any other digit, so it stands at the front of the smallest arrangement, as 30873087 gives 03780378. The gap formula 999(a−d)+90(b−c)999(a - d) + 90(b - c) is less than 10001000 only when a−d=1a - d = 1 and b−c=0b - c = 0, so for an allowed start the only result that begins with a zero is 09990999.

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 10001000. The first round gives 1000−0001=09991000 - 0001 = 0999. Keeping four places, the next rounds give

9990−0999=8991,9981−1899=8082,8820−0288=8532,8532−2358=6174,\begin{aligned} 9990 - 0999 &= 8991, \\[0.4em] 9981 - 1899 &= 8082, \\[0.4em] 8820 - 0288 &= 8532, \\[0.4em] 8532 - 2358 &= 6174, \end{aligned}

five rounds in all. If the zero of 09990999 is dropped, the digits are 99, 99 and 99, both arrangements are 999999, and the routine falls to 00 and stays there. That is a different procedure with three places, not a failure of the theorem.

Check yourself

  1. Change the number of places to three. Start from 352352, 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

532−235=297,972−279=693,963−369=594,954−459=495,\begin{aligned} 532 - 235 &= 297, \\[0.4em] 972 - 279 &= 693, \\[0.4em] 963 - 369 &= 594, \\[0.4em] 954 - 459 &= 495, \end{aligned}

and the next round gives 954−459=495954 - 459 = 495 again. So 495495 is a fixed point, and the route ends there after four rounds. With three digits a≥b≥ca \ge b \ge c the middle digit cancels, as in the 1089 trick, and each round gives 99(a−c)99(a - c). Checking all 990990 three-place starts whose digits are not all equal shows that every one of them reaches 495495 within six rounds.

  1. Start from the number 55. Follow the four-place routine to 61746174 and count the rounds. What goes wrong if 55 is treated as a one-digit number?
Show the answer

With four places the start is 00050005, whose digits are not all equal, so it is allowed. The rounds are

5000−0005=4995,9954−4599=5355,5553−3555=1998,9981−1899=8082,8820−0288=8532,8532−2358=6174,\begin{aligned} 5000 - 0005 &= 4995, \\[0.4em] 9954 - 4599 &= 5355, \\[0.4em] 5553 - 3555 &= 1998, \\[0.4em] 9981 - 1899 &= 8082, \\[0.4em] 8820 - 0288 &= 8532, \\[0.4em] 8532 - 2358 &= 6174, \end{aligned}

six rounds in all. As a one-digit number, 55 has only one arrangement, so the subtraction gives 5−5=05 - 5 = 0, and the routine stays at 00. The three leading zeros are what make 55 an allowed start.

  1. Change the number of places to two. Start from 7272 and keep two places, so that 99 is written 0909. Does the route reach a fixed point?
Show the answer

No. The rounds are 72−27=4572 - 27 = 45, then 54−45=0954 - 45 = 09, then 90−09=8190 - 09 = 81, then 81−18=6381 - 18 = 63, then 63−36=2763 - 36 = 27, and then 72−27=4572 - 27 = 45 returns to a value already seen. From there the route runs around the loop

45→09→81→63→27→45\begin{aligned} &45 \to 09 \to 81 \\[0.4em] &\quad \to 63 \to 27 \to 45 \end{aligned}

forever. With two digits a≥ba \ge b each round gives 9(a−b)9(a - b), one of the nine numbers 0909, 1818, 2727, 3636, 4545, 5454, 6363, 7272 and 8181. These go to 8181, 6363, 4545, 2727, 0909, 0909, 2727, 4545 and 6363, so none of them is sent to itself. The two-digit routine has no fixed point apart from 0000, 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.