Tuesday, 29 March 2022

Digit Sum Discoveries

I've spent quite some time working with digit sums of numbers. My Odds 'n Evens recursive algorithm involved taking a number, adding to it the sum of its odd digits and subtracting the sum of its even digits. The number associated with my diurnal age today, 26658, is a member of OEIS A246420:


  A246420

Numbers \(n\) such that (\(n\)+ digit sum of \(n\)) is a permutation of the decimal digits of \(n\).


In the case of 26658, the digit sum is 27 and adding to the number gives 26685. Such numbers account for about 0.923% of all the numbers between 1 and 26658 (permalink), or about 1 in every hundred. The initial members are:

0, 45, 234, 279, 423, 468, 612, 657, 801, 846, 1134, 1179, 1323, 1368, 1512, 1557, 1701, 1746, 1890, 1935, 2034, 2079, 2223, 2268, 2412, 2457, 2601, 2646, 2835, 3123, 3168, 3312, 3357, 3501, 3546, 3735, 3924, 3969, 4023, 4068, 4212, 4257, 4401, 4446, 4635, 4824, 4869, 5112, 5157, 5301 

I was prompted to investigate the following question: do all numbers eventually become permutations of their original digits if the process of adding the sum of digits of a number to the number is carried out repeatedly. I initially looked at 26658's neighbour, 26659. It turns out that a permutation is reached after 12 cycles and the trajectory is:

26659, 26687, 26716, 26738, 26764, 26789, 26821, 26840, 26860, 26882, 26908, 26933, 26956

However, that's not the end of the story because permutations are also reached after 1566 and 1848 cycles leading to 59266 and 65269 respectively. Clearly some permutations are not attainable because they are less than 26659 but most are larger and are not attained. Once the sum exceeds 99999, no further permutations are possible of course.

What about 26658's smaller neighbour 26657? The first permutation is reached after 42 cycles and the trajectory is:

26657, 26683, 26708, 26731, 26750, 26770, 26792, 26818, 26843, 26866, 26894, 26923, 26945, 26971, 26996, 27028, 27047, 27067, 27089, 27115, 27131, 27145, 27164, 27184, 27206, 27223, 27239, 27262, 27281, 27301, 27314, 27331, 27347, 27370, 27389, 27418, 27440, 27457, 27482, 27505, 27524, 27544, 27566.

Once again, other permutations are reached. Here is the full list:
  • 26657 leads to the permutation 27566 after 42 cycles
  • 26657 leads to the permutation 57266 after 1488 cycles
  • 26657 leads to the permutation 62675 after 1728 cycles
  • 26657 leads to the permutation 66725 after 1902 cycles
  • 26657 leads to the permutation 75266 after 2262 cycles
Once we try 26656 however, we find that no permutations are reached. Further investigation shows that most number in the vicinity of 26658 do reach a permutation, partly because most permutations are larger. As we approach 99999 of course, this likelihood diminishes. Getting back to 26658, we discover that it reaches far more than the normal number of permutations. Here is the full list (permalink):
  • 26658 leads to the permutation 26685 after 1 cycles
  • 26658 leads to the permutation 26865 after 9 cycles
  • 26658 leads to the permutation 28566 after 86 cycles
  • 26658 leads to the permutation 28665 after 90 cycles
  • 26658 leads to the permutation 52686 after 1272 cycles
  • 26658 leads to the permutation 52866 after 1280 cycles
  • 26658 leads to the permutation 56286 after 1434 cycles
  • 26658 leads to the permutation 56862 after 1457 cycles
  • 26658 leads to the permutation 58266 after 1513 cycles
  • 26658 leads to the permutation 58662 after 1528 cycles
  • 26658 leads to the permutation 62586 after 1707 cycles
  • 26658 leads to the permutation 62865 after 1719 cycles
  • 26658 leads to the permutation 65286 after 1826 cycles
  • 26658 leads to the permutation 65862 after 1849 cycles
  • 26658 leads to the permutation 66825 after 1887 cycles
  • 26658 leads to the permutation 66852 after 1888 cycles
  • 26658 leads to the permutation 68265 after 1942 cycles
  • 26658 leads to the permutation 68562 after 1953 cycles
  • 26658 leads to the permutation 68625 after 1955 cycles
  • 26658 leads to the permutation 68652 after 1956 cycles
  • 26658 leads to the permutation 82566 after 2530 cycles
  • 26658 leads to the permutation 82665 after 2534 cycles
  • 26658 leads to the permutation 85266 after 2639 cycles
  • 26658 leads to the permutation 85662 after 2654 cycles
  • 26658 leads to the permutation 86265 after 2676 cycles
  • 26658 leads to the permutation 86562 after 2687 cycles
  • 26658 leads to the permutation 86625 after 2689 cycles
  • 26658 leads to the permutation 86652 after 2690 cycles
Is this a record for five digit numbers? It would an interesting question to explore. Five distinct digits can be arranged to form a number in factorial 5 or 120 different ways. With repeated digits the number of permutations will be smaller. For example, 26658 achieves 28 out of a possible 57. There are 60 permutations altogether but the three smaller permutations (25668, 25686 and 25866) are not attainable. 

How frequent are numbers like 26656 that do not reach a permutation? Well, in the range between 26500 and 26700, there are 25 such numbers, representing 12.5%. The numbers are (permalink):

26522, 26525, 26533, 26552, 26555, 26566, 26602, 26606, 26611, 26620, 26623, 26626, 26627, 26632, 26638, 26656, 26660, 26662, 26665, 26672, 26678, 26683, 26687, 26696, 26698

Such percentages are quite variable. For example, in the range of 200 numbers from 9799 to 9999, 193 of or 96.5% of the numbers do not reach a permutation. This is because the range is close to the four digit cutoff. 

Obviously this is a topic that can be explored in far more depth but this post is a start and I'll probably follow up with further posts as I find out more.

ADDENDUM: August 18th 2023

It's interesting to look at the records for numbers of cycles taken to reach a permutation using the number + sum of digits of number recursively. Up to 100,000 the records are as follows (permalink with limit set at 100,000):

12 leads to the permutation 21 after 2 cycles
15 leads to the permutation 51 after 6 cycles
18 leads to the permutation 81 after 7 cycles
108 leads to the permutation 180 after 8 cycles
123 leads to the permutation 213 after 10 cycles
125 leads to the permutation 251 after 12 cycles
134 leads to the permutation 341 after 18 cycles
144 leads to the permutation 414 after 25 cycles
152 leads to the permutation 521 after 30 cycles
156 leads to the permutation 561 after 34 cycles
158 leads to the permutation 851 after 48 cycles
180 leads to the permutation 801 after 50 cycles
189 leads to the permutation 819 after 51 cycles
1012 leads to the permutation 2011 after 72 cycles
1027 leads to the permutation 2107 after 78 cycles
1034 leads to the permutation 3041 after 132 cycles
1037 leads to the permutation 7031 after 366 cycles
1079 leads to the permutation 9017 after 462 cycles
10005 leads to the permutation 50001 after 2002 cycles
10027 leads to the permutation 70102 after 2964 cycles
10069 leads to the permutation 90061 after 3762 cycles
10229 leads to the permutation 92120 after 3840 cycles
11199 leads to the permutation 99111 after 3900 cycles
100020 leads to the permutation 200100 after 4384 cycles
100033 leads to the permutation 300031 after 8802 cycles
100067 leads to the permutation 601070 after 20640 cycles
100117 leads to the permutation 700111 after 24198 cycles
100177 leads to the permutation 770110 after 26742 cycles
100309 leads to the permutation 900301 after 31026 cycles
100399 leads to the permutation 991030 after 33990 cycles

As can be seen, up to 100,000 the record of 3900 cycles is held by 11199 that eventually reaches the permutation 99111 that is the reversal of the original number. Up to one million, the record of 33990 cycles is held by 100399 that reaches the permutation 991030.

No comments:

Post a Comment