## Elif Lab in Just for Fun, Maths | September 1, 2021

This post takes its cue from the article “The weirdness of number 6174” (International Journal of Pure and Applied Mathematics Volume 80 No. 3 2012, 363-373, https://ijpam.eu/contents/2012-80-3/8/8.pdf) written by Yutaka Nishiyama. The fascinating article revolves around the (apparently) boring number 6174.

The core of its weirdness as a number is that (synthesising) exists a particular iterated function that operates in the set of the 4 digit numbers for which the number under consideration is an attractor and a fixed point.

This means that if we take a 4 digit number, and keep applying this operation, we will always get, in a finite (and small) number of steps, the number 6174.

The operation is defined by the following steps:

• Take a 4 digit number at the beginning of the process or take the result of the previous iteration
• Sort the digits in a descendent order obtaining a new number D
• Sort the digits in ascending order obtaining a new number A
• Take as result of the iteration the number O = D – A

It is already interesting to note that there are two levels of operations here.

On the one hand, the operations regarding the digits, i.e. the two types of sorting, work on the digits of the number. Here the digits are those relative to the representation in base 10. For each number we could choose infinite different representations (other bases, fractions etc.), but this specific one allows the process to work as intended.

On the other hand, the difference between the two reordered numbers is, instead, an operation between numbers, which means that it works for every representation.

In this post we want to show some different points of views regarding this topic. We won’t go in too much depth but we hope non-trivial elements may emerge in this process.

## Tools

In order to work better with digits, we can write an integer number as a sum:

So, in base 10, the number is the sum of the digits ai multiplied by 10i.

For a number with 4 digits we can use the more convenient notation:

We can introduce the sorting operation with the notations:

So for example (> 3251) = 5321 and (< 3251) = 1235

Using these notations the iteration step becomes:

Now, if we exclude the numbers with four identical digits, the only fixed point for this operation (in base 10) is 6174.

Which means that:

(>6174) – (< 6174) = 6174

We recall that for a function F(x) a particular value c is a fixed point if F(c)=c.

If we iterate this step (which for convenience we will call f) n-times we have the function:

It is possible to demonstrate that, if x is a 4 digit number composed of at least 2 different digits, after at most 7 steps we obtain the number 6174. This process is defined as Kaprekar’s routine after its inventor, the Indian mathematician D. R. Kaprekar.

For the 4 digit numbers composed of four identical digits (like 4444) the less interesting companion of 6174 is 0, since

and so

The 4 digit numbers (from now on we’ll write numbers instead of 4 digit numbers in order to try to be less tedious) can in this way be divided into two groups with respect to the fixed number we will reach.

As previously mentioned, the operation is a mix of 2 operations in distinct realms. Informally speaking it is like mixing logical and analogical reasoning.

In the ordering part the number is seen as a sequence of symbols with a defined ordering relation. It works on the set 0,1,2,3,4,5,6,7,8,9 where the defined ordering is:

In order to reobtain a number from the reordered sequence we must use the convention that an eventual 0 at the beginning of the sequence is to be eliminated:
(< 2301)=0123 = 123

## Generalizations

Starting from these considerations we can then follow several generalization paths.
The most followed paths are related to generalizing the number of digits and the base representation of the number. In this post we intend to follow some less traveled roads.

One of these could be expressed by the following question: taking x and y in a way that y is a permutation of x (and vice versa) what are the couples (x, y) where x-y is again a permutation of x?

This question generalizes a characteristic of 6174, using any kind of permutation in the process instead of using only the ascending/descending sorting.

We can go one step further and search a number z such that x-z is a permutation of x. In this formulation the constraint is lighter since z is not bound to be a permutation of x.
In this case, the operation x-z act as permutation, so we will call it a permutator.

## Permutators

This point of view leads to different mathematical results but, in the boundary of this article, we will limit ourselves to note that the numbers acting as permutators are always multiples of 9.

We will also limit ourselves to four-digit numbers but, of course, the reasoning presented is not bound by the number of digits.

The demonstration is straightforward.

If we subtract two permutations of a number we obtain:

This is true since every digit that remains fixed contributes with a 0, otherwise two swapped digits generate a difference of different powers of 10.

A difference of powers of 10 is always divisible by 9 since:

because:

The permutation of 4 element is a group named S4. It can be generated, for example, by the two permutations: (1,2,3,4) and (1,2) and the composition operation (which means that all permutations can be written as composition of the two generators).

Simplifying, the permutation (1,2) swaps the first two elements of a sequence, while (1,2,3,4) shifts the elements by one place to the right and sends the last element in the first one.

The combination of these two permutations generates all the possible permutations applicable on 4 elements.

We can now relate the permutation and the sum.

(1,2) is equivalent to N= abcd -> bacd

If we try to express this permutation using the difference between N and a number Z we obtain:

## The example 1234

Using as example the number 1234 and its two permutations 4321 and 3412 to show the application of (1,2) we have then:

4321 – 3421 = 103 – 102 = 1000 – 100 = 900 = 9 102

Again, using 4321 as example, we obtain:

Other examples are:

4321 – 1107 = 3214 (1107 represents (4,3,2,1) for the number 4321)

3214 – 900 = 2314 (900 represents (2,1) for the number 3214)

1234 + 90 = 1324 (+90 represents (2,3) for the number 1234)

It is interesting to note that a generic number (in the example 1234) generates, through the sum operation, a constellation of numbers that are representations of permutations.

## The number 6174

If we analyze the subject of this article, the number 6174 and its two permutations 7641 and 1467 contained in the sorting step in Kaprekar routine we have the case abcd -> dcba. This transformation is expressed by the permutation (1,4)(2,3) since a goes in d and b in c. The permutator that represents this permutation is 6174 as shown at the beginning of the post.

The first part of the permutation expressed by (1,4) can be represented with the two generators in the following way:

• First we note that taking a sequence abcd and applying four times the permutation (1,2,3,4), the elements will shift 4 times to the right (4 times the time warp). Applying 4 times the cycle is equivalent to keep the sequence untouched.
• If we apply the permutation (1,2,3,4) only once, then we swap the first two element with (1,2) and only after that  we apply the remaining 3 permutations (1,2,3,4), the elements not swapped (which means b and c) will remain in the same place as in the original sequence but the other two (a and d) will be permuted.

In formulas this reasoning will become:

The permutator is easily computed as: 7641-1647 = 5994

The permutation (2,3) can be expressed similarly as:

This (2,3) permutation si instead:  7641 – 7461 = 180

And, using the power of algebra, we have that the sum of the permutators is: 5994+180 = 6174.

If we calculate the permutators for the number 6174 we can show what we meant before when we used the term constellation. We are able to see the interesting phenomena that, since the permutators are constrained to be multiple of 9 and since the possible permutations of a sequence of 4 elements are 4!=24 (which leads to (24*24)/2=288 couples) we can easily predict we will find several elements that are the permutation one of each other.

In the following image we try to show this situation with a graph. The number (nodes) are connected if they are permutations of each other.

For example, there is the group formed by the elements: 5670, 5067, 0567 and 0675. It is a group of 4 elements (here we write the number 567 as 0567 to expose its connection with the other “siblings”).

We can also say that some permutators are shared between different couples. For example, behind the scene of this graph, the permutator 2970 is shared by 4 couples:

7146 – 4176 = 2970

4716 – 1746 = 2970

4617 – 1647 =  2970

7641 – 4671 = 2970

The couples are connected in triplets, the first one is (7146,  4176, 1746) and the second one is (7641, 4617, 1647).

The couples are also related in pairs so the cardinality of the groups is related both to the length of the circles and to the fact that a commutator is shared. In this way we can let emerge a relationship between the graph, which shows only the permutators, and the sets of numbers connected by them.

As mentioned, the permutator of 6174 contains some permutation of 6174 itself. Here is a detail of the graph:

As expected, this small group contains 6174 itself and this is a partial answer to the first question we posed in the paragraph Generalizationstaking x and y in a way that y is a permutation of x (and vice versa) what are the couples (x, y) where x-y is again a permutation of x?

## Conclusion

From here on we could (and maybe we will in another post) investigate the cardinality of these groups, the connection between groups or other interesting properties but, since this is only a small post, for now it is better to stop here our investigation.

The goals were: to play with the game provided by Yutaka Nishiyama in his article and to show how the generalization of a problem can lead to interesting ramifications. We hope to have achieved our objectives.