Showing posts with label attractors. Show all posts
Showing posts with label attractors. Show all posts

Wednesday, 7 January 2026

Code for Attractors, Vortices and Captives

Herein is an attempt to organise the code that I've gotten Gemini to write for me regarding attractors, vortices and captives.

Firstly, let's start with the ODD(+) and EVEN(-) algorithm. Here is a permalink to the code that will generate a list of attractors and vortices in decreasing order of their number of captives. It will also generate a summary and a colour-coded graphical display (see Table 1 and Figure 1). The default range is 0 to 40000.


Table 1: ODD(+) and EVEN(-)


Figure 1: red = attractor, orange = vortex, blue = captive

Secondly, let's continue with the ODD(-) and EVEN(+) algorithm. Here is a permalink to the code that will generate a list of attractors and vortices in decreasing order of their number of captives. It will also generate a summary and a colour-coded graphical display (see Table 2 and Figure 2). The default range is 0 to 40000.


Table 2: ODD(-) and EVEN(+)


Figure 2: red = attractor, orange = vortex, blue = captive

Thirdly, let's continue with the PRIME(+) and NON-PRIME(-) algorithm. Here is a permalink to the code that will generate a list of attractors and vortices in decreasing order of their number of captives. It will also generate a summary and a colour-coded graphical display (see Table 3 and Figure 3). The default range is 0 to 40000.


Table 3: PRIME(+) and NON-PRIME(-)


Figure 3: red = attractor, orange = vortex, blue = captive

Fourthly, let's continue with the PRIME(-) and NON-PRIME(+) algorithm. Here is a permalink to the code that will generate a list of attractors and vortices in decreasing order of their number of captives. It will also generate a summary and a colour-coded graphical display (see Table 4 and Figure 4). The default range is 0 to 40000.


Table 4: PRIME(-) and NON-PRIME(+)


Figure 4:  red = attractor, orange = vortex, blue = captive

Friday, 26 January 2024

Revisiting Odds And Evens

It's been a while since I posted about so-called odds and evens by which I mean the process of generating a new number from an existing one by adding its sum of odd digits and subtracting it's sum of even digits. An an example, let's consider 1234:$$1234 \rightarrow 1234+1+3-2-4=1232$$As we continue this process interesting things happen and that's what I wrote about in a paper that I published to Academia (link). Here are links to posts I've made about the topic:

Of course, if the sums of the odd and even digits are the same, the number remains unchanged. These sorts of numbers are what I termed "attractors" because other numbers, wherein there is an imbalance of odds and evens, have either these as their termini or they enter "vortices" or loops. My diurnal age today, 27326, is one such attractor which is why I was reminded of them. $$27326 \rightarrow 27326 + 7 + 3-2-2-6=27326$$Until now, I wasn't aware that they had their own OEIS sequence but they do and it is OEIS A036301 (permalink):


 A036301

Numbers whose sum of even digits and sum of odd digits are equal. 
  


The initial members of the sequence are:

0, 112, 121, 134, 143, 156, 165, 178, 187, 211, 314, 336, 341, 358, 363, 385, 413, 431, 516, 538, 561, 583, 615, 633, 651, 718, 781, 817, 835, 853, 871, 1012, 1021, 1034, 1043, 1056, 1065, 1078, 1087, 1102, 1120, 1201, 1210, 1223, 1232, 1245, 1254, 1267, 1276, 1289, 1298

I also discovered a sequence connected to what I termed "vorticals". These are the numbers that comprise a vortex into which non-balanced numbers are sucked if they do not end up in an attractor. The first instance of a vortex is that involving the numbers 11 and 13:$$ \begin{align} 11 \rightarrow 11 + 1 + 1 &= 13\\13 \rightarrow 13 + 1 + 3 &=17\\ 17 \rightarrow 17+1+7 &=25\\25 \rightarrow 25+5-2 &=28\\28 \rightarrow 28-2-8 &=18\\18 \rightarrow 18+1 -8 &=11 \end{align}$$Thus 11, 13, 17, 18, 25 and 28 are all numbers that eventually return to themselves after repeated mappings involving the odds and evens recursion. In the case of these numbers, six repetitions are needed: $$11 \rightarrow 13 \rightarrow 17 \rightarrow 25 \rightarrow 28 \rightarrow 18 \rightarrow 11$$Numbers like these are included in OEIS A124176:


 A124176

Consider the map \(f\) that sends \(m\) to \(m\) + (sum of odd digits of \(m\)) - (sum of even digits of \(m\)). Sequence gives numbers \(m\) such that \(f^k(m) \) = \(m\) for some \(k\).



This will include all the attractors, the numbers that aren't changed by the mapping and where \(k\)=1. The initial members are (permalink):

0, 11, 13, 17, 18, 25, 28, 54, 55, 64, 65, 112, 121, 134, 137, 143, 148, 155, 156, 165, 166, 173, 178, 184, 187, 198, 200, 209, 211, 216, 231, 233, 234, 237, 244, 245, 270, 275, 280, 285, 314, 336, 341, 358, 363, 385, 396, 402, 407, 410, 413, 429, 431, 432

All other numbers are what I termed "captives" because they are "captured" by either an attractor or a "vortex" that is comprised of "vorticals". The attractors and vorticals are all listed in OEIS A124176 and OEIS A036301 is a subset of this sequence because it contains only the attractors that are invariant under the mapping.

There are 2974 such numbers in the range up to 40,000. Here are the numbers from 27326 up to 40000 that belong in the sequence (for future reference):

27326, 27344, 27362, 27380, 27412, 27421, 27434, 27437, 27443, 27448, 27455, 27456, 27465, 27466, 27473, 27478, 27484, 27487, 27528, 27546, 27564, 27582, 27601, 27610, 27617, 27623, 27624, 27632, 27635, 27642, 27645, 27653, 27654, 27660, 27667, 27676, 27689, 27698, 27748, 27766, 27784, 27803, 27825, 27830, 27847, 27852, 27869, 27874, 27896, 27968, 27986, 27990, 28004, 28007, 28013, 28019, 28037, 28055, 28073, 28091, 28093, 28095, 28097, 28099, 28101, 28103, 28105, 28107, 28109, 28190, 28239, 28257, 28275, 28293, 28295, 28297, 28299, 28301, 28303, 28305, 28307, 28329, 28370, 28392, 28459, 28477, 28495, 28497, 28499, 28501, 28503, 28505, 28527, 28549, 28550, 28572, 28594, 28679, 28697, 28699, 28701, 28703, 28725, 28730, 28747, 28752, 28769, 28774, 28796, 28899, 28901, 28910, 28917, 28923, 28924, 28932, 28935, 28942, 28945, 28953, 28954, 28960, 28967, 28976, 28989, 28998, 29018, 29081, 29108, 29126, 29144, 29162, 29180, 29216, 29238, 29261, 29283, 29328, 29346, 29364, 29382, 29414, 29436, 29441, 29458, 29463, 29485, 29548, 29566, 29584, 29612, 29621, 29634, 29637, 29643, 29648, 29655, 29656, 29665, 29666, 29673, 29678, 29684, 29687, 29768, 29786, 29801, 29810, 29817, 29823, 29824, 29832, 29835, 29842, 29845, 29853, 29854, 29860, 29867, 29876, 29889, 29898, 29988, 30014, 30036, 30041, 30058, 30063, 30085, 30104, 30122, 30140, 30178, 30181, 30212, 30221, 30234, 30237, 30243, 30248, 30255, 30256, 30265, 30266, 30273, 30278, 30284, 30287, 30306, 30324, 30342, 30360, 30378, 30383, 30384, 30401, 30410, 30417, 30423, 30424, 30432, 30435, 30442, 30445, 30453, 30454, 30460, 30467, 30476, 30489, 30498, 30508, 30526, 30544, 30562, 30580, 30597, 30603, 30608, 30615, 30617, 30618, 30621, 30622, 30625, 30630, 30647, 30652, 30669, 30674, 30696, 30728, 30746, 30764, 30782, 30795, 30805, 30806, 30812, 30813, 30819, 30824, 30827, 30849, 30850, 30872, 30894, 30948, 30966, 30984, 31004, 31022, 31040, 31078, 31081, 31116, 31138, 31161, 31183, 31202, 31220, 31235, 31238, 31245, 31248, 31318, 31381, 31400, 31411, 31413, 31417, 31418, 31425, 31428, 31454, 31455, 31464, 31465, 31598, 31608, 31609, 31611, 31616, 31631, 31633, 31634, 31637, 31644, 31645, 31670, 31675, 31680, 31685, 31807, 31810, 31813, 31829, 31831, 31832, 31850, 31851, 31853, 31857, 31860, 31865, 32012, 32021, 32034, 32037, 32043, 32048, 32055, 32056, 32065, 32066, 32073, 32078, 32084, 32087, 32102, 32120, 32135, 32138, 32145, 32148, 32201, 32210, 32217, 32223, 32224, 32232, 32235, 32242, 32245, 32253, 32254, 32260, 32267, 32276, 32289, 32298, 32304, 32322, 32340, 32378, 32381, 32397, 32403, 32408, 32415, 32417, 32418, 32422, 32425, 32430, 32447, 32452, 32469, 32474, 32496, 32506, 32524, 32542, 32560, 32578, 32583, 32584, 32595, 32605, 32606, 32615, 32616, 32627, 32649, 32650, 32672, 32694, 32708, 32726, 32744, 32762, 32780, 32793, 32804, 32807, 32810, 32813, 32829, 32870, 32892, 32928, 32946, 32964, 32982, 33006, 33024, 33042, 33060, 33078, 33083, 33084, 33118, 33181, 33204, 33222, 33240, 33278, 33281, 33402, 33420, 33435, 33438, 33445, 33448, 33600, 33611, 33613, 33617, 33618, 33625, 33628, 33654, 33655, 33664, 33665, 33809, 33811, 33816, 33831, 33833, 33834, 33837, 33844, 33845, 33870, 33875, 33880, 33885, 34001, 34010, 34017, 34023, 34024, 34032, 34035, 34042, 34045, 34053, 34054, 34060, 34067, 34076, 34089, 34098, 34100, 34111, 34113, 34117, 34118, 34125, 34128, 34154, 34155, 34164, 34165, 34197, 34203, 34208, 34213, 34214, 34225, 34230, 34247, 34252, 34269, 34274, 34296, 34302, 34320, 34335, 34338, 34345, 34348, 34395, 34405, 34408, 34411, 34427, 34449, 34450, 34472, 34494, 34504, 34522, 34540, 34578, 34581, 34593, 34606, 34607, 34609, 34611, 34629, 34670, 34692, 34706, 34724, 34742, 34760, 34778, 34783, 34784, 34791, 34793, 34801, 34804, 34805, 34807, 34809, 34811, 34890, 34908, 34926, 34944, 34962, 34980, 35008, 35026, 35044, 35062, 35080, 35206, 35224, 35242, 35260, 35278, 35283, 35284, 35404, 35422, 35440, 35478, 35481, 35602, 35620, 35635, 35638, 35645, 35648, 35800, 35811, 35813, 35817, 35818, 35825, 35828, 35854, 35855, 35864, 35865, 36003, 36025, 36030, 36047, 36052, 36069, 36074, 36096, 36109, 36111, 36116, 36131, 36133, 36134, 36137, 36144, 36145, 36170, 36175, 36180, 36185, 36195, 36205, 36206, 36207, 36209, 36212, 36213, 36227, 36249, 36250, 36272, 36294, 36300, 36311, 36313, 36317, 36318, 36325, 36328, 36354, 36355, 36364, 36365, 36393, 36399, 36403, 36404, 36405, 36407, 36417, 36418, 36429, 36470, 36492, 36502, 36520, 36535, 36538, 36545, 36548, 36591, 36593, 36597, 36601, 36602, 36603, 36605, 36607, 36609, 36612, 36615, 36690, 36704, 36722, 36740, 36778, 36781, 36789, 36794, 36795, 36803, 36806, 36813, 36906, 36924, 36942, 36960, 36978, 36983, 36984, 37028, 37046, 37064, 37082, 37208, 37226, 37244, 37262, 37280, 37406, 37424, 37442, 37460, 37478, 37483, 37484, 37604, 37622, 37640, 37678, 37681, 37802, 37820, 37835, 37838, 37845, 37848, 37995, 38005, 38006, 38012, 38013, 38027, 38028, 38049, 38050, 38072, 38094, 38107, 38110, 38113, 38129, 38131, 38132, 38150, 38151, 38153, 38157, 38160, 38165, 38193, 38195, 38199, 38201, 38203, 38204, 38205, 38207, 38210, 38213, 38229, 38270, 38292, 38309, 38311, 38316, 38331, 38333, 38334, 38337, 38344, 38345, 38370, 38375, 38380, 38385, 38391, 38399, 38402, 38409, 38412, 38415, 38490, 38500, 38511, 38513, 38517, 38518, 38525, 38528, 38554, 38555, 38564, 38565, 38589, 38590, 38591, 38595, 38599, 38600, 38601, 38603, 38607, 38609, 38614, 38617, 38702, 38720, 38735, 38738, 38745, 38748, 38774, 38779, 38787, 38788, 38789, 38792, 38797, 38801, 38808, 38815, 38904, 38922, 38940, 38978, 38981, 39048, 39066, 39084, 39228, 39246, 39264, 39282, 39408, 39426, 39444, 39462, 39480, 39606, 39624, 39642, 39660, 39678, 39683, 39684, 39804, 39822, 39840, 39878, 39881

Of course, the choice of adding the odd digits and subtracting the even digits is quite arbitrary and it's perfectly acceptable to reverse this and in doing so generate a different sequence. Doing this we generate OEIS A124177:


 A124177

Consider the map \(f\) that sends \(m\) to \(m\) + (sum of even digits of \(m\)) - (sum of odd digits of \(m\) ). Sequence gives numbers \(m\) such that \(f^k(m)\) = \(m\) for some \(k\).


The initial members of this sequence are:

0, 22, 26, 27, 34, 35, 44, 49, 52, 63, 66, 78, 79, 81, 88, 99, 104, 107, 108, 112, 115, 121, 126, 133, 134, 143, 144, 151, 156, 165, 178, 187, 211, 224, 229, 232, 233, 283, 290, 314, 336, 341, 358, 363, 385, 413, 431, 467, 470, 489, 492, 516, 538, 561, 583, 615

Let's look at the first member of the sequence, 22:$$ \begin{align} 22 \rightarrow 22 + 2 + 2 &=26\\26 \rightarrow 26+2+6 &=34\\34 \rightarrow 34 + 4 - 3 &= 35\\35 \rightarrow 35-3-5 &=27\\27 \rightarrow 27+2-7 &=22 \end{align}$$Thus after five steps we arrive back at 22:$$22 \rightarrow 26 \rightarrow 34 \rightarrow 35 \rightarrow 27 \rightarrow 22$$It can be noted that "attractors", those numbers invariant under the mapping, remain the same but the "vorticals", those numbers that form "vortices" or loops, are different. There are 2966 members of this sequence in the range up to 40,000. For future reference, here are the members from 27326 to 40000:

27326, 27344, 27362, 27380, 27408, 27412, 27415, 27421, 27426, 27433, 27434, 27443, 27444, 27451, 27456, 27465, 27478, 27487, 27528, 27546, 27564, 27582, 27601, 27610, 27623, 27628, 27632, 27639, 27645, 27646, 27654, 27657, 27664, 27667, 27675, 27676, 27682, 27688, 27689, 27693, 27698, 27705, 27748, 27766, 27784, 27803, 27825, 27830, 27847, 27852, 27869, 27874, 27884, 27886, 27896, 27899, 27903, 27968, 27986, 28019, 28037, 28055, 28073, 28091, 28109, 28190, 28239, 28257, 28275, 28293, 28307, 28329, 28370, 28392, 28459, 28477, 28495, 28505, 28527, 28549, 28550, 28572, 28594, 28679, 28697, 28703, 28725, 28730, 28747, 28752, 28769, 28774, 28784, 28796, 28799, 28899, 28901, 28910, 28923, 28928, 28932, 28939, 28945, 28946, 28954, 28957, 28964, 28967, 28975, 28976, 28982, 28989, 28993, 28998, 29018, 29081, 29108, 29126, 29144, 29162, 29180, 29216, 29238, 29261, 29283, 29328, 29346, 29364, 29382, 29414, 29436, 29441, 29458, 29463, 29485, 29488, 29501, 29548, 29566, 29584, 29608, 29612, 29615, 29621, 29626, 29633, 29634, 29643, 29644, 29651, 29656, 29665, 29678, 29687, 29768, 29786, 29801, 29810, 29823, 29828, 29832, 29839, 29845, 29846, 29854, 29857, 29864, 29867, 29875, 29876, 29882, 29889, 29893, 29898, 29988, 30014, 30036, 30041, 30058, 30063, 30085, 30104, 30118, 30121, 30122, 30140, 30162, 30166, 30167, 30174, 30181, 30184, 30192, 30208, 30212, 30215, 30221, 30226, 30233, 30234, 30243, 30244, 30251, 30256, 30265, 30278, 30287, 30288, 30294, 30303, 30306, 30324, 30342, 30360, 30382, 30383, 30386, 30394, 30401, 30410, 30423, 30428, 30432, 30439, 30445, 30446, 30454, 30457, 30464, 30467, 30475, 30476, 30482, 30486, 30489, 30492, 30493, 30498, 30501, 30508, 30526, 30544, 30562, 30580, 30603, 30625, 30630, 30647, 30652, 30669, 30674, 30684, 30696, 30699, 30728, 30746, 30764, 30782, 30805, 30827, 30849, 30850, 30872, 30888, 30894, 30909, 30948, 30966, 30984, 31004, 31018, 31021, 31022, 31040, 31062, 31066, 31067, 31074, 31081, 31084, 31092, 31116, 31138, 31161, 31183, 31202, 31220, 31242, 31243, 31246, 31251, 31254, 31264, 31265, 31272, 31318, 31381, 31400, 31422, 31426, 31427, 31434, 31435, 31444, 31449, 31452, 31463, 31466, 31478, 31479, 31481, 31488, 31499, 31504, 31611, 31624, 31629, 31632, 31633, 31683, 31690, 31813, 31831, 31867, 31870, 31889, 31892, 32008, 32012, 32015, 32021, 32026, 32033, 32034, 32043, 32044, 32051, 32056, 32065, 32078, 32087, 32102, 32120, 32142, 32143, 32146, 32151, 32154, 32164, 32165, 32172, 32201, 32210, 32223, 32228, 32232, 32239, 32245, 32246, 32254, 32257, 32264, 32267, 32275, 32276, 32282, 32289, 32293, 32298, 32304, 32318, 32321, 32322, 32340, 32362, 32366, 32367, 32374, 32381, 32384, 32392, 32403, 32425, 32430, 32447, 32452, 32469, 32474, 32484, 32488, 32492, 32494, 32496, 32499, 32506, 32507, 32524, 32542, 32560, 32582, 32583, 32586, 32594, 32605, 32627, 32649, 32650, 32672, 32686, 32690, 32692, 32694, 32696, 32698, 32702, 32705, 32708, 32726, 32744, 32762, 32780, 32807, 32829, 32870, 32888, 32892, 32898, 32899, 32904, 32911, 32928, 32946, 32964, 32982, 33006, 33024, 33042, 33060, 33082, 33083, 33086, 33094, 33118, 33181, 33204, 33218, 33221, 33222, 33240, 33262, 33266, 33267, 33274, 33281, 33284, 33292, 33402, 33420, 33442, 33443, 33446, 33451, 33454, 33464, 33465, 33472, 33600, 33622, 33626, 33627, 33634, 33635, 33644, 33649, 33652, 33663, 33666, 33678, 33679, 33681, 33688, 33695, 33704, 33811, 33824, 33829, 33832, 33833, 33883, 33890, 34001, 34010, 34023, 34028, 34032, 34039, 34045, 34046, 34054, 34057, 34064, 34067, 34075, 34076, 34082, 34089, 34093, 34098, 34100, 34122, 34126, 34127, 34134, 34135, 34144, 34149, 34152, 34163, 34166, 34178, 34179, 34203, 34225, 34230, 34247, 34252, 34269, 34274, 34284, 34296, 34298, 34299, 34300, 34302, 34320, 34342, 34343, 34346, 34351, 34354, 34364, 34365, 34372, 34405, 34427, 34449, 34450, 34472, 34494, 34496, 34498, 34500, 34502, 34504, 34518, 34521, 34522, 34540, 34562, 34566, 34567, 34574, 34581, 34584, 34592, 34607, 34629, 34670, 34692, 34694, 34696, 34698, 34700, 34702, 34704, 34706, 34724, 34742, 34760, 34782, 34783, 34786, 34794, 34809, 34890, 34892, 34894, 34896, 34898, 34900, 34902, 34904, 34906, 34908, 34926, 34944, 34962, 34980, 35008, 35026, 35044, 35062, 35080, 35206, 35224, 35242, 35260, 35282, 35283, 35286, 35294, 35404, 35418, 35421, 35422, 35440, 35462, 35466, 35467, 35474, 35481, 35484, 35492, 35602, 35620, 35642, 35643, 35646, 35651, 35654, 35664, 35665, 35672, 35800, 35822, 35826, 35827, 35834, 35835, 35844, 35849, 35852, 35863, 35866, 35878, 35879, 35881, 35888, 35891, 35904, 36003, 36025, 36030, 36047, 36052, 36069, 36074, 36084, 36096, 36099, 36111, 36124, 36129, 36132, 36133, 36183, 36190, 36205, 36227, 36249, 36250, 36272, 36294, 36300, 36322, 36326, 36327, 36334, 36335, 36344, 36349, 36352, 36363, 36366, 36378, 36379, 36407, 36429, 36470, 36492, 36498, 36502, 36504, 36506, 36507, 36510, 36520, 36542, 36543, 36546, 36551, 36554, 36564, 36565, 36572, 36609, 36690, 36696, 36700, 36702, 36704, 36718, 36721, 36722, 36740, 36762, 36766, 36767, 36774, 36781, 36784, 36792, 36894, 36900, 36906, 36924, 36942, 36960, 36982, 36983, 36986, 36994, 37028, 37046, 37064, 37082, 37208, 37226, 37244, 37262, 37280, 37406, 37424, 37442, 37460, 37482, 37483, 37486, 37494, 37604, 37618, 37621, 37622, 37640, 37662, 37666, 37667, 37674, 37681, 37684, 37692, 37802, 37820, 37842, 37843, 37846, 37851, 37854, 37864, 37865, 37872, 38005, 38027, 38049, 38050, 38072, 38094, 38113, 38131, 38167, 38170, 38189, 38192, 38207, 38229, 38270, 38292, 38311, 38324, 38329, 38332, 38333, 38383, 38390, 38409, 38490, 38500, 38522, 38526, 38527, 38534, 38535, 38544, 38549, 38552, 38563, 38566, 38578, 38579, 38698, 38702, 38707, 38708, 38714, 38715, 38720, 38742, 38743, 38746, 38751, 38754, 38764, 38765, 38772, 38896, 38904, 38906, 38908, 38909, 38912, 38918, 38921, 38922, 38940, 38962, 38966, 38967, 38974, 38981, 38984, 38988, 38992, 39000, 39048, 39066, 39084, 39228, 39246, 39264, 39282, 39408, 39426, 39444, 39462, 39480, 39606, 39624, 39642, 39660, 39682, 39683, 39686, 39694, 39804, 39818, 39821, 39822, 39840, 39862, 39866, 39867, 39874, 39881, 39884, 39892

Wednesday, 9 March 2022

Higher Order Odds and Evens Trajectory

My previous post on higher order Smith numbers gave me the idea to look into what happens with the odd and even trajectory of numbers when the squares of the digits are added or subtracted instead of just the digits themselves. The odd and even rule applied repeatedly to a number \(n\) is simply to add to \(n\) its odd digits and subtract its even ones. I've devoted numerous posts to the analysis of what happens beginning with my post titled Odds and Evens on June 17th 2021.

Numbers whose sum of odd and even digits is equal are not altered when this rule is applied. 112 is an example of such a number and numbers of this type I termed attractors. Other numbers follow a trajectory that either leads them to an attractor or else they enter a loop. Such a loop I termed a vortex and the numbers that comprise a vortex I termed vorticals. 

101 is an example of a number whose trajectory leads to an attractor, in this case 134. Here is its trajectory: 101, 103, 107, 115, 122, 119, 130, 134. 199 is an example of a number that enters a vortex. Its trajectory is 199, 218, 209, 216, 209. Here we see that {209, 216} is the vortex and the vorticals are 209 and 216. Numbers whose trajectories lead to attractors or vortices I've termed captives.

The purpose of this post is to explore what happens when, instead of adding just the odd digit or subtracting the even digit, we add higher powers of those digits. Let's begin by looking at what happens to the number associated with my diurnal age today viz. 26638. Under the odd and even rule, the trajectory is 26638, 26619, 26615, 26607, 26600, 26586, 26569. The trajectory leads to the attractor 26569 that has a total of 92 captives.

What if the squares of the digits are added and subtracted? Well the trajectory then becomes 26638, 26507, 26541, 26511, 26498, 26459, 26509, 26575, 26634, 26551, 26562, 26507 and it can be seen that the trajectory immediately enters a loop or vortex {26507, 26541, 26511, 26498, 26459, 26509, 26575, 26634, 26551, 26562}. 

Let's try with the cubes of the digits. In this case, we end up with an impressively long trajectory:

26638, 25713, 26201, 25970, 27159, 28349, 28521, 28119, 28330, 27864, 27407, 28021, 27494, 28430, 27873, 28066, 27114, 27387, 27580, 27528, 27468, 27011, 27348, 27134, 27433, 27758, 28049, 28194, 28340, 27783, 27976, 29167, 30016, 29828, 29517, 30707, 31420, 31376, 31558, 31324, 31307, 31705, 32201, 32213, 32252, 32380, 31914, 32608, 31899, 32873, 32750, 33237, 33653, 33643, 33444, 33306, 33171, 33570, 34092, 34776, 35209, 36082, 35373, 35922, 36787, 36772, 37261, 37408, 37202, 37556, 37960, 38843, 37809, 38396, 38451, 38028, 37023, 37412, 37711, 38426, 37653, 37959, 39912, 41390, 42083, 41526, 41364, 41048, 40409, 41010, 40948, 41037, 41344, 41180, 40606, 40110, 40048, 39408, 39588, 39445, 40198, 40352, 40432, 40323, 40305, 40393, 41112, 41043, 40943, 41571, 41977, 43329, 44040, 43848, 42723, 43013, 43004, 42903, 43587, 43506, 43378, 43199, 44621, 44270, 44477, 44971, 45916, 46491, 46877, 46771, 47178, 47289, 47777, 49085, 49363, 49866, 49587, 50208, 49813, 49994, 52053, 52322, 52450, 52628, 52009, 52855, 52710, 53171, 53668, 52876, 52608, 51997, 53924, 54733, 55191, 56172, 56417, 56606, 56083, 55507, 56225, 56243, 56107, 56360, 56080, 55477, 56349, 56950, 57713, 58552, 58407, 58299, 59362, 60019, 60533, 60496, 60729, 61577, 62173, 62320, 62115, 62018, 61283, 60575, 60952, 61582, 60972, 61820, 61085, 60483, 59718, 60404, 60060, 59628, 59746, 60663, 60042, 59754, 61012, 60790, 61646, 60935, 61600, 61169, 61468, 60461, 59966, 61117, 61247, 61303, 61142, 60856, 60037, 60191, 60706, 60617, 60529, 61159, 61799, 63385, 62836, 61911, 62427, 62474, 62465, 62086, 61134, 60883, 59670, 60651, 60345, 60217, 60337, 60518, 59916, 61284, 60485, 59818, 59649, 60952

As can be seen, the trajectory of 238 steps finally enters a loop or vortex {60952 ... 59649}. Figure 1 shows a plot of the trajectory.


Figure 1: permalink

When we try with fourth powers we find that the trajectory consists of 599 steps:

26638, 20015, 20625, 19922, 33013, 33257, 36429, 41503, 41954, 48629, 49526, 55144, 55883, 49022, 55295, 63715, 65527, 67866, 62283, 56940, 62574, 64032, 62545, 62227, 63284, 57701, 63129, 68460, 61516, 59551, 67988, 67462, 66999, 84090, 86299, 94013, 100400, 100145, 100516, 99847, 111018, 106926, 110880, 102690, 107940, 116647, 116202, 114876, 111631, 110420, 110150, 110778, 111486, 105841, 102116, 100807, 99113, 112318, 108290, 110740, 112887, 107082, 105372, 108464, 102561, 101876, 98887, 95561, 102077, 106864, 99921, 119589, 129242, 135500, 136832, 131587, 130600, 129386, 130621, 129392, 142564, 141366, 138601, 133292, 139984, 148836, 139174, 147963, 155455, 157700, 163128, 157803, 156815, 152675, 155015, 156892, 158671, 156307, 158119, 161212, 159887, 161283, 155958, 160299, 172110, 174498, 178853, 173769, 183918, 182370, 180741, 178792, 186044, 180141, 175792, 187765, 187801, 182012, 177886, 173201, 175669, 182665, 176587, 176623, 176498, 179813, 184762, 181500, 178031, 176419, 183831, 175803, 174815, 173491, 182280, 174057, 179229, 194721, 203413, 203304, 203194, 209565, 216064, 213201, 213252, 213911, 220540, 220877, 221551, 222771, 227526, 229208, 231625, 231004, 230814, 226528, 221713, 224165, 223207, 225641, 224683, 219084, 221278, 219536, 225492, 232374, 234649, 239467, 246942, 251663, 249762, 257140, 259895, 270155, 273791, 285220, 281701, 279992, 302044, 301597, 311266, 308741, 306872, 303946, 309117, 318162, 312837, 311289, 313821, 309873, 314901, 321289, 323804, 319598, 329331, 336120, 334971, 343840, 339394, 352503, 353899, 363712, 364964, 368502, 363800, 358570, 358206, 353504, 354660, 352518, 349738, 354510, 355586, 352150, 353466, 351405, 352481, 348820, 340437, 342488, 333849, 336301, 335249, 342325, 342824, 338265, 333644, 332079, 341187, 339319, 352685, 348608, 338945, 341941, 348073, 346284, 340445, 340383, 336274, 337269, 345081, 341436, 339791, 355477, 361354, 360590, 366561, 363380, 358231, 354907, 364319, 369491, 381143, 376955, 385952, 389732, 394744, 403019, 409406, 414159, 420835, 417173, 421802, 417419, 425871, 424530, 424708, 422485, 418470, 416264, 413145, 413341, 412993, 425925, 433448, 428746, 425227, 427949, 442944, 448465, 442930, 449044, 454581, 451224, 451306, 450461, 449279, 464274, 464595, 470598, 475833, 474669, 480527, 479185, 484421, 479542, 488601, 478858, 469340, 474174, 478209, 482803, 474420, 476037, 479368, 482763, 479581, 484817, 478515, 477815, 478891, 479406, 486560, 480241, 475618, 472997, 490649, 501963, 507935, 518228, 510630, 510041, 510412, 510767, 514899, 524295, 531818, 524334, 524593, 532213, 532969, 545485, 542752, 546115, 545815, 543339, 550512, 552372, 556072, 558411, 555311, 557269, 566169, 569468, 569710, 578002, 576916, 583912, 587068, 580606, 574543, 577763, 584376, 581835, 574975, 587332, 586408, 577289, 585165, 581649, 583188, 571607, 575739, 588433, 580772, 582087, 576905, 585821, 578864, 572146, 573605, 576041, 577516, 582273, 581252, 578375, 580412, 576670, 579505, 590342, 597337, 609487, 612801, 607395, 615767, 618603, 611997, 626226, 622290, 627507, 631622, 629080, 630233, 629164, 632862, 626223, 623664, 619585, 622005, 621302, 620056, 618073, 615164, 612943, 618018, 608532, 603830, 598600, 600394, 605484, 600205, 599518, 609795, 624647, 623928, 625146, 622908, 624045, 622846, 615870, 613505, 613541, 612697, 619052, 624927, 632305, 631780, 628871, 621769, 628124, 622445, 621230, 619984, 627459, 635478, 632937, 640749, 647903, 655394, 661734, 661369, 664124, 661005, 659039, 671571, 675704, 679579, 696832, 696770, 705541, 708937, 716285, 713904, 722692, 730310, 732874, 733389, 738498, 739093, 754778, 758254, 757537, 766071, 768282, 761163, 761055, 763411, 764343, 765098, 769293, 783585, 779125, 791098, 802526, 797727, 813876, 806871, 799785, 814238, 805856, 797618, 803590, 806761, 802475, 801133, 797201, 808549, 807287, 803881, 791675, 802368, 792945, 808821, 796518, 800714, 798764, 804479, 808833, 796707, 809175, 814667, 810125, 806640, 799696, 819188, 813463, 807978, 811149, 813361, 808133, 800104, 795753, 808447, 802144, 797521, 809494, 818008, 805721, 804636, 797773, 814019, 816230, 810904, 813114, 808846, 795006, 803297, 808228, 795908, 807960, 811530, 808142, 799679, 822868, 809252, 812310, 808281, 795978, 810431, 806162, 799459, 821912, 824347, 822205, 818686, 803807, 798097, 811925, 815001, 811532, 808128, 795825, 801925, 805000, 801529, 804604, 798700, 805967, 810162, 804756, 802134, 797848, 800763, 797853, 805826, 796947, 813319, 815948, 814687, 807345, 806100, 800709, 805575, 805755, 805935, 809731, 814679, 817994, 829166, 829024, 831201, 827172, 827847, 824185, 816347, 813182, 805057, 804612, 798949, 816681, 805899, 811454, 807473, 808004, 799556, 815033, 811725, 810641, 804995, 814390, 816681

Once again, a loop or vortex is entered {816681 ... 814390}. Figure 2 shows a plot of the trajectory.


Figure 2: permalink

With fifth powers, the trajectory is even longer (971 steps) and, as can be seen, the trajectory initially plunges into negative number territory.

26638, -21471, -37224, -53186, -16011, -8238, 57087, 61058, 23640, 15051, 21303, 21758, 8891, 2405, 4474, 18209, 44459, 103561, 99155, 223504, 225784, 211860, 171286, 147519, 225478, 211554, 216750, 228875, 183207, 167458, 145823, 115368, 78194, 120259, 182370, 166621, 143263, 134918, 160420, 151589, 184122, 150268, 112818, 47253, 66372, 67838, 11576, 23734, 39971, 175120, 195022, 257133, 277520, 314195, 375590, 457939, 595188, 594952, 718244, 700204, 715955, 801187, 752460, 763560, 768183, 711922, 787716, 797594, 951407, 1029365, 1083975, 1130432, 1129864, 1147315, 1166469, 1201168, 1160595, 1218120, 1185291, 1214668, 1165294, 1218638, 1145539, 1210059, 1272203, 1289158, 1285766, 1257347, 1293274, 1368286, 1287410, 1270395, 1349588, 1345446, 1337967, 1423341, 1421749, 1495527, 1576578, 1575899, 1684287, 1626727, 1644726, 1643902, 1694363, 1737323, 1771635, 1800843, 1734527, 1770454, 1805146, 1766705, 1787893, 1815264, 1776791, 1878487, 1812774, 1812566, 1767341, 1792400, 1867201, 1843434, 1808081, 1709779, 1878299, 1947637, 2031744, 2046715, 2057816, 2037173, 2071242, 2086930, 2105646, 2092164, 2142350, 2144631, 2135020, 2138325, 2109105, 2171249, 2246019, 2296205, 2350507, 2373775, 2427775, 2480233, 2446863, 2396706, 2457221, 2476034, 2483228, 2416815, 2378342, 2361779, 2446878, 2388293, 2382228, 2316807, 2293282, 2319678, 2355202, 2361599, 2475258, 2464459, 2515753, 2542147, 2559968, 2643740, 2650934, 2704519, 2782445, 2767497, 2868135, 2798160, 2833441, 2799080, 2901185, 2930561, 2985171, 3031354, 3034185, 3004005, 3006349, 3057084, 3043467, 3050936, 3105820, 3076389, 3112187, 3096440, 3145908, 3174534, 3192905, 3314340, 3313022, 3313688, 3241106, 3232519, 3295116, 3349727, 3441820, 3407216, 3415435, 3420124, 3418256, 3380025, 3350836, 3314146, 3304810, 3271505, 3294774, 3385600, 3348667, 3316616, 3293776, 3379117, 3472268, 3447686, 3414368, 3372263, 3381959, 3470901, 3545977, 3644109, 3693578, 3732501, 3752888, 3674727, 3716559, 3791133, 3867720, 3861001, 3820702, 3804920, 3830388, 3732813, 3717550, 3757658, 3757221, 3794140, 3868192, 3854141, 3822695, 3844504, 3812032, 3779687, 3848856, 3745120, 3764240, 3771434, 3803487, 3754220, 3773307, 3824457, 3809784, 3819323, 3846302, 3805188, 3710253, 3730640, 3739133, 3815962, 3837804, 3788537, 3760226, 3761660, 3755383, 3746401, 3753628, 3733470, 3766789, 3811375, 3799027, 3950950, 4075541, 4096551, 4153051, 4158522, 4130917, 4205994, 4325137, 4344500, 4344796, 4410047, 4423783, 4406228, 4363572, 4375158, 4364667, 4356341, 4350129, 4411491, 4467471, 4490238, 4514682, 4475184, 4459277, 4552985, 4587585, 4547207, 4581866, 4502880, 4439413, 4495877, 4556849, 4579556, 4655987, 4696525, 4745216, 4755293, 4836586, 4757842, 4759733, 4854983, 4849816, 4833506, 4795549, 4934656, 4979473, 5129380, 5158998, 5217811, 5204946, 5257264, 5271457, 5310266, 5298051, 5330551, 5340413, 5341977, 5436985, 5460959, 5576507, 5611720, 5623846, 5577838, 5552409, 5619777, 5724597, 5822454, 5793824, 5839224, 5867785, 5834337, 5821206, 5783724, 5786882, 5700702, 5737409, 5832416, 5794185, 5842500, 5814926, 5835501, 5812352, 5786014, 5764379, 5851610, 5817318, 5771959, 5929922, 6110098, 6128605, 6083379, 6119177, 6204067, 6204266, 6179850, 6218288, 6112145, 6106441, 6088843, 5981982, 6037638, 6006611, 5983285, 5983259, 6075050, 6090331, 6142091, 6192310, 6243796, 6303287, 6280004, 6238404, 6196023, 6239732, 6308234, 6267120, 6268312, 6220172, 6229108, 6247550, 6261775, 6282931, 6301616, 6278533, 6258375, 6241099, 6350366, 6330649, 6373608, 6342581, 6304350, 6299161, 6401677, 6418716, 6386181, 6305338, 6268648, 6178728, 6138999, 6275846, 6246402, 6228738, 6172412, 6180357, 6159989, 6299718, 6394048, 6410748, 6384964, 6393888, 6347343, 6355055, 6360022, 6344649, 6385317, 6365192, 6412026, 6395387, 6434310, 6424973, 6491216, 6533659, 6583892, 6572965, 6639487, 6666242, 6634050, 6620842, 6571434, 6581786, 6520631, 6508416, 6462198, 6471872, 6463887, 6398825, 6387898, 6357917, 6446173, 6445624, 6430093, 6480828, 6373692, 6434450, 6426970, 6486218, 6404075, 6414183, 6371836, 6340810, 6299486, 6368208, 6287331, 6264049, 6305466, 6284482, 6209058, 6230656, 6210664, 6186281, 6105163, 6092981, 6170504, 6181637, 6150369, 6197235, 6268652, 6215617, 6219967, 6339289, 6417297, 6501129, 6555497, 6631928, 6642869, 6644766, 6628421, 6579014, 6649196, 6742943, 6809186, 6787148, 6746427, 6762409, 6821657, 6793238, 6829004, 6846453, 6799453, 6928926, 6998640, 7067394, 7151500, 7174559, 7272449, 7363000, 7372517, 7426275, 7454150, 7475160, 7503100, 7523276, 7552418, 7541652, 7555878, 7533331, 7554236, 7568704, 7563875, 7563438, 7542288, 7495596, 7627951, 7715932, 7811932, 7855233, 7845976, 7900196, 8027326, 8003768, 7947506, 8034494, 8057946, 8095359, 8187182, 8105655, 8074487, 8040517, 8026658, 7948663, 7975418, 8037415, 8023799, 8126147, 8101356, 8064182, 7989815, 8062310, 8021978, 8032267, 8008709, 8019029, 8104328, 8037980, 8048543, 7984327, 8043409, 8067885, 7981737, 8058683, 7955971, 8113934, 8139679, 8234284, 8166879, 8161648, 8079538, 8093226, 8111910, 8138195, 8135078, 8089718, 8067271, 8060310, 8020010, 7987211, 8047076, 8039122, 8065583, 7998764, 8108908, 8069654, 8082484, 7982100, 8025157, 8015415, 7987875, 8034934, 8059653, 8084651, 8013441, 7978870, 8022804, 7956180, 7994618, 8087956, 8093625, 8115466, 8069249, 8145747, 8147671, 8139719, 8242101, 8208247, 8158430, 8095239, 8183905, 8180787, 8116098, 8101837, 8053353, 8027564, 8005896, 7994758, 8115803, 8053637, 8033511, 8004356, 7966156, 8021810, 7956244, 8025369, 8047210, 8030194, 8055695, 8083575, 8041339, 8067083, 8010821, 7945255, 8029430, 8054898, 8017744, 8016543, 7978344, 8036434, 7994328, 8095652, 8120375, 8107751, 8111724, 8094710, 8136775, 8133214, 8099878, 8136479, 8171011, 8155054, 8130638, 8057813, 8012453, 7981998, 8110417, 8093435, 8122303, 8089958, 8112877, 8080925, 8077531, 8081746, 8024218, 7957595, 8118682, 8012572, 7999673, 8202901, 8229119, 8314387, 8265121, 8227640, 8202815, 8140341, 8105770, 8109742, 8151775, 8158873, 8080745, 8034117, 8017377, 8035274, 8021625, 7984143, 8025427, 8011503, 7982105, 8028287, 7946726, 8022781, 7973989, 8152225, 8125612, 8088131, 7990072, 8141752, 8127862, 8071294, 8113327, 8097822, 8108078, 8026582, 7956331, 8028023, 7962666, 8007386, 7951124, 8029051, 8058426, 7987183, 8014554, 7985989, 8117532, 8104909, 8189216, 8174923, 8217199, 8319306, 8338298, 8299497, 8459627, 8497008, 8506304, 8468104, 8392745, 8438145, 8373930, 8417747, 8433353, 8403658, 8332690, 8351649, 8372499, 8473823, 8424524, 8391745, 8437178, 8404476, 8377667, 8380011, 8314720, 8297947, 8415835, 8355769, 8397574, 8459813, 8455671, 8437161, 8412645, 8373147, 8373456, 8352306, 8315341, 8285162, 8214912, 8240107, 8223091, 8249552, 8280995, 8336650, 8291941, 8376217, 8369499, 8505321, 8479015, 8524205, 8496599, 8635303, 8598613, 8587719, 8617972, 8670060, 8638547, 8584386, 8480650, 8409439, 8492964, 8568438, 8464702, 8438885, 8310157, 8297566, 8328195, 8325045, 8297714, 8356554, 8324604, 8282223, 8216802, 8143427, 8125630, 8088423, 7989306, 8083910, 8077667, 8079768, 8099119, 8243500, 8213044, 8178440, 8127664, 8095096, 8175775, 8199679, 8353090, 8382982, 8343906, 8361873, 8305855, 8249937, 8351261, 8314055, 8286757, 8250152, 8223571, 8210915, 8240291, 8265485, 8197367, 8249730, 8292005, 8321347, 8304817, 8255308, 8196233, 8215193, 8244812, 8177165, 8173362, 8150080, 8087670, 8047972, 8106811, 8033502, 8004313, 7971008, 8030904, 8056404, 8016937, 8052493, 8081086, 7975007, 8087602, 8031065, 7993890, 8155319, 8188095, 8151966, 8165822, 8095572, 8144878, 8061334, 8020253, 7990789, 8168782, 8079478, 8105581, 8046297, 8080553, 8021510, 7991837, 8111025, 8081353, 8019429, 8103704, 8086963, 8065167, 8036780, 7980518, 7993964, 8179361, 8214918, 8207377, 8225241, 8194479, 8294569, 8374192, 8416468, 8333333, 8302023, 8269677, 8313988, 8275220, 8262288, 8156112, 8118664, 8036554, 8001479, 8043544, 8011072, 7995081, 8100344, 8065772, 8061935, 8083809, 8044797, 8102644, 8060021, 8019446, 8035904, 8064529, 8085103, 8022936, 8041620, 8000021, 7967222, 8052013, 8022582, 7960075, 8048087, 7965566, 8024344, 7988715, 8018968, 7971938, 8091126, 8109601, 8128108, 8029774, 8088613, 7982777, 8076254, 8054586, 7986500, 8024937, 8067212, 8043412, 8008808, 7877736, 7904663, 7964186, 7990699, 8235926, 8257735, 8265042, 8226535, 8192420, 8217614, 8192823, 8186516, 8108555, 8052395, 8085137, 8039777, 8116722, 8092923, 8178432, 8128891, 8089606, 8067567, 8055986, 8047973, 8107087, 8075166, 8046779, 8097874, 8123977, 8184084, 8083733, 8035733, 8023626, 7975485, 8040606, 7991262, 8118328, 8020237, 8004455, 7975889, 8065190, 8086821, 7980710, 8040606

The trajectory once again enters a loop {8040606 ... 7980710}. Figure 3 shows the trajectory.



Figure 3: permalink

I'll leave off there and powers higher than 5 may prove rather unwieldy. It's not possible to make generalisations at this early stage but it would seem that the trajectories are far more volatile and lengthy once we start dealing with powers of digits. The trajectories may end up favouring vortices instead of attractors. 

One general observation is that the trajectories will always tend to rise rather than fall because there are the odd digits (1, 3, 5, 7 and 9) with an average value of 5 outweighing the even digits (0, 2, 4, 6, 8) with an average value of 4.

Friday, 16 July 2021

Kaprekar's Routine

I first encountered the algorithm that Wolfram MathWorld calls Kaprekar's Routine last year and actually made a post about it titled Birth Year Magic. I've created this post because I was reminded of the similarity between Kaprekar's Routine and the Odd-Even Algorithm that I've written about in a number of previous posts:



Dattaraya Ramchandra Kaprekar is something of an inspiration for me because our situations are similar academic-wise.

In Kaprekar's Routine, numbers get mapped to what are called fixed points (attractors in my terminology) or end up in loops (vortices in my terminology). Here is what Wolfram MathWorld has to say about the algorithm:

The Kaprekar routine is an algorithm discovered in 1949 by D. R. Kaprekar for 4-digit numbers, but which can be generalised to \(k\)-digit numbers. To apply the Kaprekar routine to a number \(n\), arrange the digits in descending \( n^{'} \) and ascending \( n^{''} \) order. Now compute \( K(n)=n^{'}-n^{''} \) (discarding any initial 0s) and iterate, where \(K(n)\) is sometimes called the Kaprekar function. The algorithm reaches 0 (a degenerate case), a constant, or a cycle, depending on the number of digits in \(k\) and the value of \(n\). The list of values is sometimes called a Kaprekar sequence, and the result K(n) is sometimes called a Kaprekar number (Deutsch and Goldman 2004), though this nomenclature should be deprecated because of confusing with the distinct sort of Kaprekar number.

In base-10, the numbers n for which \(K(n)=n\) are given by 495, 6174, 549945, 631764, ... (OEIS A099009). Similarly, the numbers \(n\) for which iterating \(K(n)\) gives a cycle of length \(k \geq 2\) are given by 53955, 59994, 61974, 62964, 63954, 71973, ... (OEIS A099010).

Iterating the Kaprekar map in base-10, all 1- and 2-digit numbers give 0. Exactly 60 3-digit numbers, namely 100, 101, 110, 111, 112, 121, 122, 211, 212, 221, ... (OEIS A090429), reach 0, while the rest give 495 in at most 6 iterations. Exactly 77 4-digit numbers, namely 1000, 1011, 1101, 1110, 1111, 1112, 1121, 1211, ... (OEIS A069746), reach 0, while the remainder give 6174 in at most 8 iterations. The value 6174 is sometimes known as Kaprekar's constant (Deutsch and Goldman 2004). This pattern breaks down for 5-digit numbers, which may converge to 0 or one of the 10 constants 53955, 59994, 61974, 62964, 63954, 71973, 74943, 75933, 82962, 83952.

I developed an SageMath algorithm (permalink) to determine the behaviour of numbers of any length over a given range. In my earlier post, my algorithms only applied to three and four digit numbers. Here is the behaviour for numbers in the range from 26400 to 26425:

26400 --> [26400, 63954, 61974, 82962, 75933, 63954]

26401 --> [26401, 62964, 71973, 83952, 74943, 62964]

26402 --> [26402, 61974, 82962, 75933, 63954, 61974]

26403 --> [26403, 61974, 82962, 75933, 63954, 61974]

26404 --> [26404, 61974, 82962, 75933, 63954, 61974]

26405 --> [26405, 62964, 71973, 83952, 74943, 62964]

26406 --> [26406, 63954, 61974, 82962, 75933, 63954]

26407 --> [26407, 73953, 63954, 61974, 82962, 75933, 63954]

26408 --> [26408, 83952, 74943, 62964, 71973, 83952]

26409 --> [26409, 93951, 85932, 74943, 62964, 71973, 83952, 74943]

26410 --> [26410, 62964, 71973, 83952, 74943, 62964]

26411 --> [26411, 52965, 70983, 94941, 84942, 73953, 63954, 61974, 82962, 75933, 63954]

26412 --> [26412, 51975, 81972, 85932, 74943, 62964, 71973, 83952, 74943]

26413 --> [26413, 51975, 81972, 85932, 74943, 62964, 71973, 83952, 74943]

26414 --> [26414, 51975, 81972, 85932, 74943, 62964, 71973, 83952, 74943]

26415 --> [26415, 52965, 70983, 94941, 84942, 73953, 63954, 61974, 82962, 75933, 63954]

26416 --> [26416, 53955, 59994, 53955]

26417 --> [26417, 63954, 61974, 82962, 75933, 63954]

26418 --> [26418, 73953, 63954, 61974, 82962, 75933, 63954]

26419 --> [26419, 83952, 74943, 62964, 71973, 83952]

26420 --> [26420, 61974, 82962, 75933, 63954, 61974]

26421 --> [26421, 51975, 81972, 85932, 74943, 62964, 71973, 83952, 74943]

26422 --> [26422, 41976, 82962, 75933, 63954, 61974, 82962]

26423 --> [26423, 41976, 82962, 75933, 63954, 61974, 82962]

26424 --> [26424, 41976, 82962, 75933, 63954, 61974, 82962]

26425 --> [26425, 42966, 71973, 83952, 74943, 62964, 71973]

All the numbers end in a loop of one type or another. Let's compare what happens to today's number (I'm 26402 days old) under the two different algorithms:

  • Kaprekar's Routine:

    26402
    --> [26402, 61974, 82962, 75933, 63954, 61974]

  • Odd Even Algorithm: 

    26402
    -->[26402, 26388, 26367, 26363, 26355, 26360, 26349]
Kaprekar's Routine causes the number to end up in a loop [61974, 82962, 75933, 63954, 61974] while the Odd Even Algorithm leads to an attractor, or fixed point, 26349. Go back to my post Birth Year Magic to find out more about Kaprekar.

Monday, 21 June 2021

Odds and Evens: Statistics

 This post won't make much sense unless my previous posts on this topic are read:


Figure 1

Figure 1 shows the sums of odd and even digits in the number systems from 10 down to 2. It also shows the ratio between the two sums. With even bases (10, 8, 6, 4 and 2), it can be seen that the sum of odd digits are larger than the sum of even digits. With odd bases (9, 7, 5 and 3), the situation is reversed.

In my previous post on Binary Odds and Evens, it was apparent that no vortices were possible and thus there were only captives and attractors. In base 10, captives could be captured by attractors and vortices. This same situation should prevail in the bases from 9 down to 3. However, the main focus of this post is to look at the first 100,000 integers and enumerate them according to the nomenclature that I have developed. What I discovered is that there are:
  • 3725 attractors
  • 58977 captives of these attractors
  • 914 vortices with a total of 3975 vorticals
  • 34223 captives of these vortices
Figure 1 shows a graphical representation of this data:

Figure 1: link

The average number of vorticals in a vortex is almost exactly four. The maximum size of a vortex in the range chosen is 11 and there are two of these:
  • 81191, 81193, 81195, 81197, 81199, 81201, 81203, 81204, 81205, 81207, 81211 
  • 18211, 18191, 18193, 18195, 18197, 18199, 18201, 18203, 18204, 18205, 18207
The minimum size is of course is two and there are many of these e.g. 198 --> 200 --> 198. 


Here is a permalink to the SageMathCell program that calculated this information. I did need to do a fair bit of tinkering to get it all to work but I'm very pleased with the final result.

Saturday, 19 June 2021

Binary Odds and Evens


In my earlier post, titled Odds and Evens, I investigated what happened to decimal numbers when the odd-even recursive process was applied to them. In this process, the sum of a number's odd digits is added to the number and the sum of its even digits subtracted. In those numbers where the sum of the odd and even digits is equal, the number remains unchanged by this process and is termed an attractor, using the nomenclature that I developed. 112 is the first such number and any permutations of the digits of an attractor are also attractors. Thus 112 and 211 are also attractors. Less than 4% of numbers are of this types.

Most numbers are what I termed captives and the process leads them to either an attractor or a vortex. The steps in this process are termed its trajectory and as an example, let's use 5. It's trajectory is 5, 10, 11, 13, 17, 25, 28, 18 because the final number, 18, leads back to 11. The sequence of numbers 11, 13, 17, 25, 28, 18 constitutes a vortex from which there is no escape. On the other hand, 145 has a trajectory of 145, 147, 151, 158, 156 because 156 is an attractor and so no further change is possible. In my last post, titled Attractors, Vortices and Captives, I explored the odd-even decimal universe in more detail.


Figure 1: 150 is an attractor in binary but not in decimal

Once we use binary numbers however, a fundamental difference arises when the odd-even recursive process is applied. There are only 1's and 0's with the former being odd and thus are added while the latter, even though even, don't contribute. Thus there can be no vortices because return to an earlier number is not possible. The process always lead to increasingly bigger numbers and the process will never end. If we don't want the process to go on forever, then some intervention is necessary. One way to terminate the process is to stop when an equal number of 1's and O's is reached. If a number already has this balance then it is an attractor and remains unchanged. This is the approach followed in this post. At the end of this post, I'll suggest another approach.

This is a fundamentally different process. See Figure 1. If applied to decimal numbers, it would mean that a number like 201334 would be an attractor because it has three even digits and three odd digits, even though the sum of the odd digits is 7 and the sum of the even digits is 6. However, the process can be modified to accommodate our binary problem. We could say:

  1. For non-binary number systems, an attractor is defined as a number whose sum of even and odd digits is equal. The odd-even recursive process, as applied to non-binary numbers that are not attractors, is to add the sum of the odd digits and subtract the sum of the even digits so that a new number is generated. This process is repeated until an attractor is reached or the numbers enters a vortex, or endless loop of numbers.

  2. For the binary number system, an attractor is defined as a number with the same number of 1's and 0's. The odd-even recursive process, as applied to binary numbers that are not attractors, is to add the sum of the 1's so that a new number is generated. This process is repeated until an attractor is reached. Vortices are not possible in the binary number system.

Let's use 2149 as an example. As a binary number its trajectory would be:

100001100101, 100001101010, 100001101111, 100001110110

This number has a trajectory of length 3 because 100001110110 is an attractor, having an equal number of 1's and 0's. This attractor in decimal form is 2166. Some numbers take quite a few steps to reach an attractor. 243 is an example of such a number because it takes 59 steps to reach the attractor 527. I've created an algorithm to look at the first 30,000 numbers and I've discovered that the record is set by 15998 with a trajectory of length of 2228 steps, leading to a final number of 33231 (an attractor in the binary number system). Here is a permalink to that program.

In the range between 1 and 30000, attractors total 2353 or 7.84% while there are 27646 captives representing 92.16%.

I mentioned that I'd propose an alternative approach to the odd-even recursive process as applied to binary numbers. This approach involves treating 0's as -1 and 1's as simply 1's. Thus a binary number like 10010110 shown in Figure 1 would still be an attractor but vortices are now possible because of subtraction and these could draw in numbers in the same way that attractors do. The downside is that it treats 0's quite differently than in the higher bases. I'll try to investigate this approach in a future post.