Ever since I wrote my last essay on 142857 — The Cyclic Number, I have been scanning the numbers-landscape to find other interesting numbers that I have been missing out on. This is how I came across 6174, a number that appears most ordinary on the surface. But just like the cyclic number, the deeper I tried to understand 6174, the more interesting and bizarre the mathematics got.
I will start this essay by explaining what makes 6174 (the 4-digit number) so special. Following this, in a quest to understand why this number appears repeatedly in places we do not quite expect, I will explore similar mathematical behaviour in lower dimensions such as with 2-digit numbers and 3-digit numbers.
The lower dimensional behaviour is easier to grasp and offers a nice basis to start understanding what could be going on with 6174, which is what I will be tackling finally. If you are intrigued about this number or numbers in general, you might enjoy reading this essay. Let us begin.
The Recurring Fixed Point
The mathematical phenomenon that I am about to share with you was originally presented by an Indian mathematician named D.R. Kaprekar in 1959. He proposed an algorithm/function where we consider any 4-digit number, except numbers that feature the same digits. For example, 5793 would be allowed while 0000 or 9999 would not be allowed (you will realise why shortly).
Since I just mentioned 5793, why don’t we consider that number for the first illustration? Kaprekar’s algorithm/function involves the following three steps:
Step 1: Create a new number ‘A’ by rearranging the digits in their descending order. For 5793, A = 9753.
Step 2: Create a new number ‘B’ by rearranging the digits in their ascending order. For 5793, B = 3579.
Step 3: Find the difference between A and B. For 5793, A – B = 6174.
Please make a note of this algorithm as we will be applying it on multiple occasions throughout this essay. As you can see, for 5793, the algorithm results in 6174. This could just be a fluke, right?
Why don’t we test that hypothesis out? Let us consider 6859 and apply Kaprekar’s algorithm once more:
Step 1: For 6859, A = 9865
Step 2: For 6859, B = 5689
Step 3: For 6859, A – B = 4176
Were you secretly expecting 6174? If so, do not fret yet. Let us apply Kaprekar’s algorithm recursively to 4176 as well:
Step 1: For 4176, A = 7641
Step 2: For 4176, B = 1467
Step 3: For 4176, A- B = 6174
This time, we indeed arrive at 6174! The first time around (for 5793), we got 6174 immediately when we applied Kaprekar’s algorithm. The second time around (for 6859), we had to apply Kaprekar’s algorithm recursively to the first number that resulted (4176) to arrive at 6174.
In this case, 4176 is called a Kaprekar number and 6174 is called Kaprekar’s constant. It turns out that when we apply Kaprekar’s algorithm to any 4-digit number (that doesn’t feature the same 4 digits) recursively, the number of steps to reach 6174 varies from 1 to 7. In other words, it might take a while, but we would inevitably end up with 6174.
At this point, if you are the curious type, you might be wondering what happens when we apply Kaprekar’s algorithm to 6174. Why don’t we find out?
Step 1: For 6174, A = 7641
Step 2: For 6174, B = 1467
Step 3: For 6174, A – B = 6174
How fascinating! We end up with 6174 once again. In other words, regardless of the path we take, we will end up with a fixed point at 6174. This is why 6174 is called Kaprekar’s constant, whereas the intermediate numbers are called Kaprekar numbers. The original number we started with (like 5793) is called a seed number.
This essay is supported by Generatebg
But why does this pattern occur? To begin understanding the underlying reasons, I would like to take you through the 2-digit and the 3-digit case. The details we are about to uncover are both revealing and surprising. Let us start with the 2-digit case.
The Limit Cycle
To begin, let us onsider the number 90 and apply Kaprekar’s algorithm to it:
Step 1: For 90, A = 90
Step 2: For 90, B = 09
Step 3: For 90, A – B = 81
Beyond this point, we will be applying Kaprekar’s algorithm recursively multiple times. So, to be more concise, I will just represent the results (Kaprekar numbers) like so: Seed number → Kaprekar number → Kaprekar number → Kaprekar number …
The sequence of Kaprekar numbers that follows the original number is called a Kaprekar sequence. For the number 90, the Kaprekar sequence looks like so:
90 → 81 → 63 → 27 → 45 → 09 → 81 → …
Do you notice anything particularly of interest here? Take a moment if you need to. For starters, ALL of these numbers are multiples of 9. Secondly, notice how at step 1, we arrived at 81, and at step 6 (I am considering 90 as step 0 here), we arrived at 81 again. If we continued to apply Kaprekar’s algorithm beyond this point, the Kaprekar sequence from 81 through 09 would just repeat infinitely.
In the context of number theory/sequences, such a cycle is called a Limit Cycle.
It could be a fluke that we ended up with multiples of 9 since we started with 90. So, let us start with another unrelated seed number: 16. The Kaprekar sequence for 16 is as follows:
16 → 45 → 09 → 81 → 63 → 27 → 45 → …
Isn’t that fascinating? We once again end up with a sequence involving multiples of 9 that keeps repeating itself every 6 steps.
Our little discovery that the Kaprekar numbers are multiples of 9 is useful in and of itself. But we could go one step further and prove that the Kaprekar numbers for 2-digits MUST be multiples of 9.
Let ‘a’ and ‘b’ be the two digits of the original number such that a > b. Consequently, from the first step of Kaprekar’s algorithm, we would get A = ab. From the second step, we would get B = ba. Finally, using the third step, we could write the formula for any Kaprekar number as follows:
Kaprekar number (K) = ab – ba
In the first number (from the left), ‘a’ represents the 10’s place (in the decimal system) and ‘b’ represents 1’s place (in the decimal system). For the second number, it is the other way around. As a result, we could represent the same formula as follows:
On the one hand, this relation proves that all Kaprekar numbers in the 2-digit case MUST be multiples of 9. On the other hand, this relation gives us a way to predict the next Kaprekar number given one. Using this, we could establish a table of all possible Kaprekar sequences. This would be cumbersome, but it would still be better than shooting blind with probabilities (the entropy is significantly reduced with a finite table).
When we started investigating this behaviour, we knew almost nothing. But now, we have come quite some way. What more can we understand/learn? Let us proceed with the 3-digit case and find out.
The Limit Cycle Vanishes
Since we have already done the grunt work of laying out the basics in the previous cases, I can afford to be a little quicker with the 3-digit case. Let me start by laying out the Kaprekar sequence for the 3-digit seed number 741:
741 → 594 → 495 → 495
Wait, what? Our limit cycle from the 2-digit case has vanished, giving rise to Kaprekar’s constant for the 3-digit case (495). Just to be thorough, let me present to you the Kaprekar sequences for two more seed numbers as follows (142 and 480):
142 → 297 → 693 → 594 → 495 → 495
480 → 792 → 495 → 495
Do you notice anything particularly of interest here? Again, take a moment if you need to. First of all, all of the Kaprekar numbers feature 9 as their middle digit. Secondly, the sum of the first and last digits is always 9. Consequently, the sum of all the digits for 3-digit Kaprekar numbers is always 18. Why is this?
We could use the same mathematical procedure we used for the 2-digit case to understand why. Let the seed number be represented by abc, where all three digits are not equal and a ≥ b ≥ c. The, the formula for Kaprekar number is as follows:
K = abc – cba
For the first number (from the left), ‘a’ takes the 100’s place, ‘b’ takes the 10’s place, and ‘c’ takes the 1’s place. For cba (the second number), it is the other way around. Consequently, we could rewrite the formula as follows:
This formula tells us two things:
1. All 3-digit Kaprekar numbers are multiples of 99 (and 9).
2. Any 3-digit Kaprekar number could be computed using JUST the first and last digits of the seed/Kaprekar number.
You could also see the elimination of the middle digit (9) as noise/entropy reduction. With this, we have a way of predicting the behaviour of Kaprekar’s algorithm/function for the 3-digit case as well. At this point, we are finally prepared to tackle the 4-digit case (6174).
The Equivalence Class
Just like we defined the seed number for the 2-digit case and the 3-digit case, let us say that the seed number for the 4-digit uses the digits ‘a’, ‘b’, ‘c’, and ’d’, where a ≥ b ≥ c ≥ d (but not all equal). Consequently, we could write the formula for 4-digit Kaprekar numbers as follows:
K = abcd – dcba
Here, for the first number (from the left), ‘a’ takes the 1000’s place, ‘b’ takes the 100’s place, ‘c’ takes the 10’s place, and ‘d’ takes the 1’s place. For dcba (the second number), it is the other way around. Consequently, we could rewrite the formula as follows:
This relation proves that 4-digit Kaprekar numbers are also multiples of 9. Furthermore, it gives us a way to predict the Kaprekar sequence behaviour. Without this relation, we would have to create a table of the 9990 possible 4-digit numbers (leading zeroes are allowed for the Kaprekar algorithm).
At this point, you might be wondering how exactly this formula helps us. Focus on the terms (a – d) and (b -c). These are essentially the differences between the outer digits and the inner digits respectively. Let us say that m = (a – d) and n = (b – c). We could rewrite the 4-digit Kaprekar formula as follows:
K(m, n) = 999m + 90n
It turns out that multiple 4-digit numbers lead to the same (m, n) combination. A set of mathematical objects that share a common property are collectively grouped into an equivalence class.
For instance, the equivalence class for (8, 1) contains 9981, 9871, 9651, 9541, 9431, 9321, 9211, 8870, 8760, 8650, 8540, 8430, 8320, 8210, 8100, and all their permutations. This significantly reduces the number of possibilities.
Excluding numbers with the same digits, similar to (8, 1), there exist only 54 classes in total that converge to Kaprekar’s constant (6174). This makes it significantly easier to predict the behaviour of Kaprekar sequences in the 4-digit case.
If you have read this essay so far, I assume that you found all of this fascinating. So do I. But what use does this serve? Well, as far as I researched, the notion of the Kaprekar sequence does not find much use outside of cryptography. While that is a bit of a disappointment, I would say that it is a net win for mathematics even if all it ever did was create excitement amongst math-lovers.
With that, I conclude this essay and hope that you enjoyed reading it.
If you’d d like to get notified when interesting content gets published here, consider subscribing.
Further reading that might interest you:
- How To Really Solve The Packing Spheres Puzzle
- Math Vs. Physics – What Makes Them So Different?
- Russell’s Paradox – A Lesson On How To Crash Mathematics
If you would like to support me as an author, consider contributing on Patreon
Reference and credit: David Deutsch and Benjamin Goldman.
There is an typo in your 3-digit factoring statement. It should read “factoring 999 and 90 out” instead of “factoring 999 and 99 out”
Thank you very much for pointing this out! I have corrected the error now.