Another interesting 4-digit number: 6174

7 min read Original article ↗

Besides having the number looking inconspicuously like my birthday , how else is this number worthy of mention? Consider taking a 4-digit number with at least one different digit (i.e. 2222 is a no-no but 2225 is okay); if you have trouble finding one, take the last four digits of your mobile number. Rearrange the number in A) Ascending order and B) Descending order to form two new 4-digit numbers. Take their absolute difference and repeat the entire process with this new difference. For example, let’s consider 7472. Rearranging the number gives us A) 2477 and B) 7742. Their absolute difference is 7742-2477=5265. Repeating the process gives us:

6552-2556 = 3996
9963-3699 = 6264
6642-2466 = 4176
7641-1467 = 6174
7641-1467 = 6174

Wait, did we just end up in a loop at 6174?

Interestingly, what we have here is a 4-digit Kaprekar Constant. In 1949, D. R. Kaprekar announced his discovery of this very interesting property. Apply the transformation described above to any 4-digit number (except 0000, 1111, 2222, …, 9999) and you are guaranteed to reach this magical number 6174 within SEVEN iterations. We call the transformation a Kaprekar Routine, K(n_b), where n is the number in base b. In base 10, we have 2 Kaprekar Constants: a 4-digit one that we have just seen, and a 3-digit number. Can you work out what it is?

Simultaneous Equations and a Unique Solution

Instead of going through the Kaprekar Routine, let’s try understanding the mechanism behind the process. Say we have a 3-digit number abc such that 9\geq a \geq b \geq c \geq 0. Then from the vertical subtraction that we are used to, we get:

\begin{array}{r}abc \\ -cba \\ \hline ABC \end{array}

And with some careful consideration (because c could be less than a), we can say that:

C=10+c-a,
B = 10+b-1-b =9,
A= a-1-c.

Finding the 3-digit Kaprekar Constant meant that we are looking for a unique (unordered) solution where (A,B,C)=(a,b,c). Given that we know B=9, we can further simplify the search (with new unknown holders to prevent confusion x\geq y) to:

\begin{array}{r}9xy \\ -yx9 \\ \hline A9C \end{array}

and that:

C=10+y-9=y-1,
A = 9-1-y =8-y,
\Rightarrow A+C=9.

This is very useful information because we now know that there are only so many possibilities (A,C)=\{(1,8), (2,7), (3,6), (4,5)\}. For there to be a unique solution, however, we need the restriction such that (A,C)=(x,y) and the only possibility is (A,C)=(x,y)=(4,5). There we have it, our 3-digit Kaprekar Constant is 495.

This is made possible because we are able to extract 3 equations given 3 variables. Likewise, we can repeat the above arithmetic calculations with the 4-digit case where abcd such that 9\geq a \geq b \geq c \geq d \geq 0:

\begin{array}{r}abcd \\ -dcba \\ \hline ABCD \end{array}

This will give us four equations with four unknowns:

D=10+d-a,
C = 10+c-1-b =9+c-b,
B = b-1-c,
A = a-d

with the unique solution such that (A,B,C,D) = (a,b,c,d) = (7,6,4,1).

Digits and Bases

Mathematicians have always looked beyond the decimal system. We wonder if the same patterns observed in base 10 works the same in other bases. In their 1978 paper determining all 4-digit Kaprekar Constants, Hasse and Prichett referred to the constant as the Invariant of the Transformation (which we now know as K(n), the Kaprekar Routine). If you want to read more about the property of Invariance, take a look at my previous blog post! They have also termed base as g-adic so in case you referred to their paper, note the difference in the labels. In yet another paper by Y. Nishiyama, these invariants are called kernels (due to the study of objects called cycles which is also mentioned as T-cycles in Hasse & Prichett’s paper). The idea of me bringing this up is that different mathematicians use different names and notations so it pays to be aware!

Say we were to have a number n with k digits in base b, X_0X_1...X_{k-1} with digits arranged in descending order, we can write that as:

n=b^{k-1}X_0+ b^{k-2}X_1 + ... + b^0X_{k-1}.

Then applying the transformation:

K(n)=(b^{k-1}X_0+ b^{k-2}X_1 + ... + b^0X_{k-1})-(b^{k-1}X_{k-1}+ ... +b^0X_0),
K(n)=(b^{k-1}-1)(X_0-X_{k-1}) + (b^{k-2}-b)(X_1-X_{k-2}) + ....

Notice the coefficients of the digits are in the form b^m - b^n where m>n. This is worth noting since factoring gives us b^n(b^{m-n}-1) = b^n(b-1)(1+b+...+b^{m-n-1}), then we can say that regardless of digits and bases, K(n) is always divisible by b-1. This wasn’t as direct but it made sense if we were to look back at base 10 and realize that both Kaprekar constants 495 and 6174 are divisible by 9.

Further work has been conducted by Eldridge & Sagong who observed a property that for any 3-digit K(n_b), it will always end up in the form of (D-1)(b-1)(b-D) where D is the difference between the largest and smallest digits. For example, in base 10, a 3-digit number 234 with D=2 will have K(234)= (2-1)(10-1)(10-2)= 1 9 8 (bad notation here I apologize).

Hassel and Prichett discussed in their paper, proving that any 4-digit numbers in (base or g-adic) g=2, g=4, and g \equiv 0 \text{ mod } 5 has a Kaprekar constant. For example, if we have apply this to the above generalization, we get

K(X_0X_1X_2X_3) =(b^3-1)(X_0-X_3) + (b^2-b)(X_1-X_2).

If we let X_0-X_3=d and X_1-X_2=d', then according to their theorem,

g=2: (d,d')=(1,0) \text { or } (1,1),
g=4: (d,d')=(3,1),
g \equiv 0 \text{ mod }5: (d,d')=(3,1) \cdot \frac{g}{5}.

This makes sense! If we have g=10\equiv 0 \text{ mod }5, then (d,d')=(3,1)\cdot 2=(6,2). Matching this to the above (a,b,c,d) = (7,6,4,1) shows us this is correct!

Seven Iterations?

It is fascinating how any 4-digit number can reach 6174 within 7 iterations. How about the case of 3-digit numbers? Let’s investigate!

Consider how K(abc)= (100a+10b+c)-(100c+10b+a)=99(a-c). If we let d=a-c, then there are a total of 9 possibilities since 1\leq d \leq 9. If we were to:

  • multiply that by 99 (i.e. to find 99(a-c)),
  • rearrange the resulting number in descending order, and
  • remove the repeated values,

we will end up with five entries remaining: 990, 981, 972, 963, and 954. Try arranging these numbers into a schematic diagram and you get a linear one:

990 \rightarrow 981 \rightarrow 972 \rightarrow 963 \rightarrow 954

What this means is that given any 3-digit number (except the usual 000, 111, …, 999), putting them through the Kaprekar routine will definitely lead you to one of the above five entries. This also means that for 3-digit numbers, at most 5 iterations are necessary.

We can apply this to 4-digit numbers. Consider K(abcd)= 999(a-d)+90(b-c)=999\delta+90\delta'. Do note that since 1 \leq \delta \leq 9 and 0 \leq \delta' \leq 9, there are a grand total of 9 \times 10=90 possibilities. It is best to tabulate this due to the huge amount of numbers. Also, note that we can first eliminate repetitions WLOG by letting \delta \geq \delta'. Following the steps above results in 30 remaining entries and arranging them in a schematic diagram gives us the following:

Schematic Diagram leading to 7641 (6174) by Y. Nishiyama

Unlike the linearity of the 3-digit case, notice how any 4-digit numbers, when transformed, will land on any one of these entries. This shows that there are at most 7 iterations!

Conclusions

I touched a bit on recreational mathematics in this post. I have demonstrated how we can apply the algorithm and arrive at an invariant. Alternatively, we could attempt to arrive at this conclusion by solving simultaneous equations or via a schematic diagram (with the latter providing us with more information i.e. number of iterations). I have also discussed briefly how mathematicians are interested in this phenomenon in not only other number of digits, but also in other bases.

How is this relevant to educators? In addition to the Big Idea of Invariance, this post demonstrated another Big Idea – Diagrams. Diagrams are succinct visual representations that could communicate important information like properties of objects or summarize their characteristics. In this very example, it enables us to show the number of iterations required at maximum in order to reach the Kaprekar constant. Another highlighted theme of mathematics here is that of Operations and Algorithms. Kaprekar routine, an algorithm which includes the mathematical operation of subtraction, is one of the most accessible (no need for worksheets!) and simplest algorithm that can be introduced to elementary school students. Making use of the maximum number of iterations, teachers can get students to practice subtracting 4-digit numbers. If the students did not arrive at 6174 within 7 iterations, we know that an error must have occured somewhere. What’s more, it is fun and fascinating!

Papers I have referred to:


[1] Hanover, D. (2017). The Base Dependent Behavior of Kaprekar’s Routine: A Theoretical and Computational Study Revealing New Regularities. arXiv: General Mathematics.
[2] Hasse, H.; Prichett, G. D. (1978). The determination of all four-digit Kaprekar constants. Journal Fur Die Reine Und Angewandte Mathematik (Crelle’s Journal)297, 113.
[3] Nishiyama, Y. (2012). The Weirdness of Number 6174. International Journal of Pure
and Applied Mathematics 80
.3: 363–373.