The magic of the Kaprekar constant, the number 6174 that always returns to itself

The magic of the Kaprekar constant, the number 6174 that always returns to itself

There Kaprekar constant, 6174so called in honor of the Indian mathematician Dattatreya Ramachandra Kaprekar who discovered it, is a mysterious number that always comes back on itself. If we order its figures from the largest to the smallest, and then from the smallest to the largest, we get the numbers 7641 and 1476 which, subtracted from each other, give 6174 again. But not only! Taken a any number of 4 figures that are all different from each other – for example 3520 – if we write its figures in first decreasing order (5320) and then growing (0235), we subtract them e We repeat this procedure at least seven times Sooner or later we will get 6174! It is the so -called Kaprekar algorithm. It is a procedure that for the numbers of 4 digits works like this:

  1. It starts from a number, for example 3520
  2. The figures are ordered in decreasing order obtaining a new number, 5320 in our case
  3. The figures are ordered in growing order obtaining a new number, 0235 in our case
  4. The small number is subtracted from the large number obtaining a new number, 5320-0235 = 5085 in our case

This algorithm can be repeated on the result obtained, whenever we want, for example we started from 3520 and we can continue:

  1. 5320-0235 = 5085
  2. 8550-0558 = 7992
  3. 9972-2799 = 71737
  4. 731-1377 = 6354
  5. 6543-3456 = 3087
  6. 8730-0378 = 8352
  7. 8532-2358 = 6174
  8. 7641-1467 = 6174

At the 7th passage we arrived at the Kaprekar constantin a sense we have fallen into trap since, from this moment on, we can repeat the operation as many times we want but we will no longer move from number 6174, in fact it is possible to demonstrate that:

By applying the Kaprkar algorithm starting from any number of 4 digits, of which at least 2 different from each other, you reach the number 6174 at most in 7 steps.

This result also applies to the numbers of 1, 2 or 3 digits as long as you add zeros to the left in order to make them 4 digits, for example to apply the algorithm to number 43 we must write it in form 0043. The only exceptions are for the numbers consisting of 4 equal digits (e.g. 3333) since in these cases the procedure will immediately bring number 0 (33333333 = 0) (0000-0000 = 0000).

But is it something that only works with the numbers of 4 digits? In fact, no, there is also one Kaprekar constant for the numbers of 3 digitsit is the number 495in fact if we calculate 954-495 we get 495.

For numbers a 6 digits There are even two of numbers that return to themselves, 631764 And 549945. However, in many cases, as for numbers at 1, 2, 5 or 7 figures, there are no constants of Kaprekar, but at maximum cycles, or of the sequences of numbers that follow one another after the other cyclically.

But how do we be sure that only 6174 and 495 (and the other Kaprekar constants) return to themselves? In fact, there is nothing mysterious, it is not about magic, and it can be demonstrated with a reasoning, based on the functioning of the subtraction in columnwhich however is quite elaborate. Alternatively we can use the brute force and try to apply the algorithm to all the numbers consisting of a given amount of figures. The latter strategy is feasible especially when you have a computer and deal with relatively small numbers. It allows you to collect all data on the number of steps which serve, from time to time, for trap In a constant of kaprekar, data that can be represented graphically, as in the figure below.

Image
Each square represents the number of steps necessary to reach a fixed point, both in the case of 4 digits (left) and 3 digits (right). Blu means multiple passages (7 left, 6 on the right) green means less passages, red means 0 steps.

This graphic representation shows that 6174 And 495 They are the only constants of Kaprekar (not null) for the numbers of 4 digits and 3 digits. The large square on the left, 100 × 100 side refers to all the numbers of 4 digits, arranged in files of 100, where the first square in the upper left corresponds to the number zero and is red because with the Kaprkar algorithm the zero returns to itself, the other point red corresponds precisely to the number 6174. Where the squares are color blue intense means that the algorithm requires the maximum number of steps before ending in Kaprekar’s constant, while if the color is intense green is required 1 step onlyintermediate colors represent intermediate situations. Similarly, the vertical band on the right of the figure represents the case of the 1000 numbers of three digits, arranged in 100 files of 10. In both cases the figures show evident regularity that form pleasant graphic motifs … at least from the point of view of a mathematician!