I've written extensively about this algorithm in previous posts and even uploaded a PDF to Academia (link). For some reason I decided to reread what this PDF and this motivated me to get Gemini Pro 3.0 to try its hand at writing some Python code to implement this algorithm across a chosen range of numbers. Of course, I'd already done this previously using SageMath but my algorithm timed out on SageMathCell above 100,000 and I thought that any code that Gemini created would be far more efficient than any code that I could write. I tested it out on SageMathCell for a range up to one million but it still timed out. However, on a range up to 100,000, it only took a few seconds. I tried to run the code in my Jupyter notebook using the range up to one million but it spat the dummy. No problem, I'm mainly interested in the range up to 40,000 given my focus on my diurnal age. Here is a permalink to the algorithm on SageMathCell,
Here was the prompt that I gave Gemini:
Implement the following program in Python. Here are the details:
\( \textbf{Odd Even Algorithm} \)
\( \textbf{The Basic Algorithm:}\)
Let’s describe the basic algorithm first. It takes 0 or any positive integer as input, computes the sum of the number’s odd digits and the sum of the number’s even digits. The sum of the number’s odd digits is added to the number while the sum of the number’s even digits is subtracted. This process is repeated until a stable number is reached, meaning the sums of odd and even digits are equal, OR a loop is entered.
\( \textbf{Nomenclature:}\)
I’m choosing to call stable numbers (sums of odd and even digits are equal) ATTRACTORS because under the algorithm the trajectory of many numbers will lead to such an attractor. 0 is the first such attractor and 112 is the next.
Numbers that lead back to themselves I’m calling VORTICALS. An example is 11 because its trajectory is 11, 13, 17, 25, 28, 18, 11. Similarly 13 is a vortical because its trajectory is 13, 17, 25, 28, 18, 11, 13. All these numbers lead back to themselves and collectively I call this collection of verticals a VORTEX. It can be represented as [11, 13, 17, 25, 28, 18] but any vortical in it can be placed first and only the cyclic order needs to be preserved.
Numbers whose trajectories lead to a vortex or an attractor are called CAPTIVES. 9 is a captive of a vortex because its trajectory is 9, 18, 11, 13, 17, 25, 28, 18 leads it to the vortex [18, 11, 13, 17, 25, 28].
\( \textbf{Applying the algorithm to a range of numbers:}\)
I’m interested in selecting a range of numbers (let’s say from 0 to 100,000) and applying the algorithm to each number in this range. What I want to keep track of are:
- Display list of attractors and their total number
- Display list of the captives of each attractor and the number of these captives for each
- Display a ranking of the attractors in order of number of captives (highest to lowest)
- Display list of vortices (plural of vortex) together with the vorticals that comprise them
- Display the captives of each each vortex and how many captives each has
- Display of ranking of vortices in order of number of captives (highest to lowest)Display overall statistics: number of attractors, number of vorticals, number of captives of attractors, number of captives of vortices.
Gemini carried these instructions out perfectly as the implemented code revealed. Here is a
link to its response. I ran the program using a restricted range up to 40,000 and copied the output to a Google document (
link). I can now search this document to find details concerning an attractor or vortex. For example, consider these forthcoming attractors: 28019, 28037, 28055, 28073 and 28091. Here are the results concerning their number of captives:
- 28019 has three captives (27951, 27971, 27993)
- 28091 has 138 captives (28100, 28102, 28104, 28106, 28108, 28110, 28111, 28112, 28113, 28114, 28115, 28116, 28117, 28118, 28121, 28123, 28127, 28129, 28139, 28140 ... and 118 more)
This of course is a very useful tool and I'll be making use of it for my diurnal number investigations. This was the summary generated for numbers in the range up to 40000:
- Total Attractors Found: 1527
- Total Vortices Found: 428
- Total Unique Vorticals: 1451
- Total Captives of Attractors: 20417
- Total Captives of Vortices: 16610