SEARCHING FOR KAPREKAR’S CONSTANTS: ALGORITHMS AND RESULTS

We examine some new results on Kaprekar's constants, specifically establishing the unique 7-digit (in base 4) and 9-digit (in base 5) Kaprekar's constants and showing that there are no 15-, 21-, 27-, or 33-digit Kaprekar's constants.


Introduction
The number 6174 arises in a semifamous problem in recreational mathematics: take any 4-digit number which uses more than one digit and find the difference between the numbers formed by writing the digits in descending order and ascending order (e.g., starting with 4083 yields 8430 − 0348 = 8082). Iterate this process using the difference as the new 4-digit number. It was first discovered by the Indian mathematician Kaprekar [5] that this process leads in at most 7 steps to the number 6174, a fixed point of the iteration. 6174 is thus known as Kaprekar's constant. This curious example reportedly sparked interest on several campuses, including Berkeley and MIT [1]. Several authors have examined the generalized problem using different lengths and/or different bases. In this context, an n-digit number in base b is called a Kaprekar's constant if it is a fixed point under the descending/ascending difference operation (sometimes called Kaprekar's routine) and every nontrivial n-digit number eventually is transformed to that fixed point by iterating the operation. Our work continues this line of inquiry, establishing the unique 7-digit (with b = 4) and 9-digit (b = 5) Kaprekar's constant and shows that there are no 15-, 21-, 27-, or 33-digit Kaprekar's constants.
3000 Searching for Kaprekar's constants: algorithms and results The following generalizations fix the number of digits and consider the bases which may have a Kaprekar's constant.
Hasse [2] investigated the 2-digit problem. The only Kaprekar constant here is 01 in base 2. The real interest in this case is the rich structure of the cycles which occur in the various bases. Consider the digraph formed by taking the n-digit numbers as vertices and edges which connect each number to its successor under the Kaprekar routine. (This object is sometimes called a unary algebra.) Since the graph is finite and every node has outdegree 1, every walk along the digraph eventually becomes cyclic. A Kaprekar constant occurs when the only cycle which appears is a unique loop.
For the 2-digit case, if b = 2 r s − 1, where s is odd, then any multiple of s will eventually die out by producing 00. This behavior is unique to the n = 2 case, with the trivial exception of starting with a number with only one digit. Otherwise, the cycles consist of nodes of the form 2 r t with t odd. The length of these cycles is precisely where k = ind 4 m means that k > 0 and minimal such that 4 k ≡ 1modm. (Most of this result can be found in [2], however with less concision and completeness.) Jordan [4] showed the only bases which have a 3-digit Kaprekar's constant are the even ones. For b = 2k, the Kaprekar's constant is k − 1 2k − 1 k. Eldridge and Sagong elaborated on the cycle structure for this case in [1].
Hasse and Prichett [3] found that the only bases which have a 4-digit Kaprekar's constant are b = 5 and b = 4 j · 10. The respective Kaprekar's constants are 3032 and Prichett [7] showed that the only bases b which have a 5-digit Kaprekar are congruent to 3 mod 6, with b = 9 as the only nonexample. The Kaprekar's constant for b = 6t + 3 is 4t + 2 2t 6t + 2 4t + 1 2t + 1. (2. 3) The new results basically follow a program hinted at in a final paragraph of [7]. Some of the results seem suggested there, but they are not made explicit.

Explanations of the programs and the notation
In order to implement Kaprekar's routine as efficiently as possible, we will employ the following reduction. Given an N-digit number, arrange its digits in descending order, say can just as easily be obtained by Needless to say, we do not wish to store the N/2 trailing zeros. We think of our N-digit numbers as being represented by the N/2 leading digits. For example, 6174 would be represented by 7 − 1 and 6 − 4, or in our node notation, 6 : 2 . The number in (2.3) is written as 4t + 2 : 2t + 1 in node notation. Fixing the number of digits and the base, we define a directed edge from each node to its successor. Following a path of directed edges inevitably leads to a previously visited node, and thereby a cycle. Clearly, there is a Kaprekar's constant if and only if the graph has a 1-cycle as its only cycle.
The programs designed to make this determination may be found at http://math.scu. edu/∼bwalden/kaprekar. The first, kap1.cc, computes all the cycles for a specified number of digits and a specified range of bases. The second, kap2.cc, only computes cycles until it finds a cycle that is not a 1-cycle or more than one cycle. The amount of sorting required is minimal: even for large values of N, the differences split into two almost sorted lists, which are easily fixed and merged.

The 7-digit case
Running the programs for the 7-digit case, the patterns which emerge lead to discovering the following lemma. Proof. The full cycles are listed in Appendix B. We will omit all but one of the computations. The rest are similar. In the case where b = 4k + 1, we start with 3k + 1 : 2k + 1 : The difference thus belongs to the node 3k + 2 : 2k + 1 : k + 2 . Continuing, 3k + 2 2k + 1 k + 2 0 0 0 0 − 0 0 0 0 k + 2 2k + 1 3k + 2 3k + 2 2k + 1 k + 1 4k 3k − 2 2k − 1 k − 1 . (4.2) The difference belongs in the node 3k + 1 : 2k + 1 : k − 1 , creating a 2-cycle. Proof. This constant is mentioned as an example in [4]. The output of kap2.cc shows that the only Kaprekar constant for 7-digit numbers with b ≤ 21 is the one given in the statement of the theorem. But Lemma 4.1 shows that there can be no Kaprekar constant for any base b > 21.
The numerical evidence leads to the following.

Special 1-cycles for the (6k + 3)-digit case
In this section, we will construct a rich family of 1-cycles in the case where N = 6k + 3. is a 1-cycle.
Proof. Performing Kaprekar's routine in this case yields a difference whose leading 3k + 1 digits are followed by the digit b − 1, and then by the 3k We now apply this line of inquiry to the manageable smaller cases. For N = 6k + 3 we need only check the bases b ≤ (6k + 2)(3k + 3) which satisfy the condition (5.5). The computer checking leads to the following result.