Showing posts with label graph. Show all posts
Showing posts with label graph. Show all posts

Monday, 6 July 2026

Recurring Digital Invariant Variant (RDIV) Algorithm

Let's consider the following algorithm (formally called the Recurring Digital Invariant Variant or RDIV algorithm - see this link for an explanation of the name):

  • choose a number \(n\)
  • let \(k\) be the number of digits in \(n\)
  • raise each digit of \(n\) to the \(k\)-th power and add the results
  • call the new number \(n\) and repeat
Let's use \(n=14\) as an example:

  • \(14 \rightarrow 1^2 + 4^2 = 17\)
  • \(17 \rightarrow 1^2 + 7^2 = 50\)
  • \(50 \rightarrow 5^2 + 0^2 = 25\)
  • \(25 \rightarrow 2^2 + 5^2 = 29\)
  • \(29 \rightarrow 2^2 + 9^2 = 85\)
  • \(85 \rightarrow 8^2 + 5^2 = 89\)
  • \(89 \rightarrow 8^2 + 9^2 = 145\)
  • \(145 \rightarrow 1^3 + 4^3 + 5^3 = 190\)
  • \(190 \rightarrow 1^3 + 9^3 + 0^3 = 730\)
  • \(730 \rightarrow 7^3 + 3^3 + 0^3 = 370\)
  • \(370 \rightarrow 3^3 + 7^3 + 0^3 = 370\) 
370 is a narcissistic number as explained in my post Narcissistic, D-Powerfull and Friedman Numbers. The trajectory of any number under this algorithm will either end with a narcissistic number (as was the case with 14) or it will enter a loop (as is the case with 28218). The latter has the following trajectory (permalink):

==================================================
RDIV TRAJECTORY ANALYSIS FOR INPUT: 28218
==================================================
Full Trajectory Visited:

28218, 65601, 18678, 90120, 59082, 94974, 136953, 595181, 824837, 646826, 406272, 168529, 855931, 825565, 355739, 681798, 1220035, 80569, 102718, 379859, 1459029, 9660576, 6524445, 485466, 379273, 768261, 473170, 240124, 8321, 4194, 7074, 5058, 5346, 2258, 4753, 3363, 1539, 7268, 7809, 13058, 36137, 25070, 19964, 126899, 1371747, 2489202, 6896889, 16417266, 10869443, 61641187, 25966788, 86116067, 27580867, 47154531, 6683686, 5316235, 440689, 848433, 533938, 811397, 911965, 1125165, 436317, 169860, 886898, 1626673, 1665667, 2021413, 18829, 124618, 312962, 578955, 958109, 1340652, 376761, 329340, 537059, 681069 -> [loops back to 886898]

Loop Entry Point:   886898 (encountered at step 65)

Pre-period Length:  64 step(s) before entering cycle

Cycle Length:       14 distinct number(s) in the loop

Canonical Cycle:    18829, 124618, 312962, 578955, 958109, 1340652, 376761, 329340, 537059, 681069, 886898, 1626673, 1665667, 2021413

==================================================

Figure 1 shows a graph of its trajectory:

Figure 1: permalink

I've incorporated this algorithm into my daily number analysis.

Friday, 17 April 2026

Digit Equations Continued

My post of March 2024 titled Forming Equations from the Digits of a Number expanded an idea that I'd broached in a far earlier post in August of 2013. I'm relating in this current post on my interaction with Gemini in helping me to determine all the numbers between 1 and 40000 that can't be rendered as digit equations. Firstly let's recap what the rules for rendering are:

  • only digits can be manipulated not combinations of digits, that is no concatenations
  • the order of the digits cannot be changed
  • only the operations of addition, subtraction, multiplication, division and exponentiation are allowed
  • division can be divided into e.g. 2 | 8 or divided by e.g. 8 / 2
  • an unlimited number of brackets can be used
  • unary operations are allowed meaning any digit can be changed into its negative.
What I got Gemini to do was to create a list of all the numbers from 1 to 40000 that CANNOT be rendered a digit equations. There are 4839 numbers that qualify in that range and of course the early numbers predominate. Figure 1 shows a graph of the distribution.


Figure 1

What is striking about the graph is that between 10979 and 20294, there are only two numbers that CANNOT be rendered as digit equations. These numbers are 15795 and 15975, each a permutation of the other's digits. This means that, out of the 9313 numbers from 10980 to 20293 inclusive, there are only two that CANNOT be rendered as digit equations. The other 9311 can be. There is another smaller gap between 21027 and 22525 (exclusive) in which there are only three numbers (21037, 21049 and 21059) that cannot be rendered.

Here is a link to the Gemini chat that I had which was long and involved: 


Here are the numbers that CANNOT be rendered as digit equations from 28000 to 40000:

28027, 28049, 28108, 28120, 28210, 28255, 28270, 28290, 28308, 28383, 28395, 28429, 28474, 28494, 28558, 28585, 28672, 28708, 28759, 28849, 28908, 28959, 29049, 29059, 29109, 29120, 29130, 29169, 29210, 29212, 29229, 29230, 29239, 29240, 29260, 29269, 29280, 29284, 29292, 29293, 29296, 29309, 29379, 29392, 29397, 29409, 29410, 29420, 29432, 29433, 29460, 29467, 29479, 29480, 29490, 29494, 29509, 29510, 29514, 29530, 29537, 29559, 29569, 29572, 29573, 29577, 29587, 29589, 29590, 29595, 29596, 29598, 29599, 29609, 29659, 29673, 29679, 29692, 29697, 29739, 29749, 29769, 29779, 29793, 29794, 29796, 29797, 29809, 29859, 29937, 29959, 30292, 30295, 30424, 30464, 30497, 30592, 30637, 30727, 30738, 30757, 30794, 30797, 30828, 30837, 30848, 30857, 30868, 30938, 30949, 30959, 30968, 31027, 31607, 31667, 31677, 31707, 31708, 31717, 31767, 31778, 31787, 31788, 31807, 31808, 31818, 31877, 31878, 31887, 31898, 31908, 31977, 31987, 31988, 31998, 32535, 32597, 32737, 32957, 32979, 33585, 33597, 33727, 33737, 33747, 33828, 33858, 34647, 34737, 34746, 34747, 34757, 34758, 34847, 34858, 34949, 34959, 35105, 35106, 35235, 35253, 35325, 35352, 35358, 35385, 35397, 35405, 35445, 35450, 35470, 35477, 35499, 35527, 35605, 35606, 35650, 35656, 35665, 35670, 35747, 35775, 35835, 35838, 35853, 35868, 35874, 35885, 35886, 35905, 35927, 35949, 35959, 35995, 36105, 36106, 36107, 36474, 36505, 36506, 36556, 36560, 36565, 36566, 36590, 36706, 36707, 36717, 36760, 36766, 36767, 36776, 36780, 36807, 36868, 36885, 36886, 37027, 37106, 37107, 37108, 37117, 37167, 37176, 37177, 37178, 37187, 37188, 37198, 37207, 37210, 37237, 37240, 37255, 37270, 37273, 37295, 37299, 37306, 37308, 37327, 37337, 37347, 37372, 37373, 37374, 37437, 37447, 37457, 37464, 37473, 37474, 37475, 37484, 37507, 37508, 37547, 37574, 37592, 37606, 37607, 37608, 37617, 37618, 37650, 37666, 37667, 37670, 37671, 37676, 37680, 37690, 37698, 37699, 37806, 37807, 37808, 37817, 37818, 37855, 37860, 37870, 37871, 37877, 37878, 37887, 37888, 37890, 37891, 37907, 37908, 37929, 37952, 37953, 37979, 37997, 38107, 38108, 38109, 38118, 38120, 38167, 38168, 38177, 38178, 38187, 38188, 38189, 38197, 38198, 38208, 38283, 38307, 38309, 38310, 38328, 38340, 38355, 38356, 38358, 38360, 38365, 38370, 38382, 38383, 38385, 38388, 38390, 38408, 38458, 38535, 38538, 38548, 38558, 38562, 38568, 38574, 38583, 38584, 38585, 38586, 38607, 38608, 38652, 38658, 38668, 38685, 38686, 38707, 38708, 38709, 38717, 38718, 38745, 38755, 38760, 38777, 38778, 38780, 38781, 38787, 38788, 38790, 38907, 38908, 38909, 38917, 38918, 38950, 38960, 38961, 38965, 38966, 38967, 38970, 38980, 38981, 38988, 38989, 38998, 38999, 39027, 39108, 39109, 39178, 39188, 39198, 39199, 39279, 39292, 39297, 39409, 39449, 39459, 39494, 39495, 39509, 39528, 39537, 39549, 39558, 39559, 39594, 39595, 39708, 39729, 39779, 39792, 39797, 39808, 39809, 39817, 39818, 39855, 39860, 39867, 39870, 39871, 39888, 39889, 39890, 39891, 39898, 39899, 39927

In the SageMath program on my Jupyter notebook, I've added some additional code, courtesy of Gemini, that will render the number associated with my diurnal age as a digit equation or announce failure if a rendering is not possible. Of course, I'll try to create the equation myself before looking at the program's output. Today I'm 28138 days old:

Monday, 30 March 2026

Number Testing for the Recaman Sequence

An interesting exercise is to determine how many iterations are required to reach a given number within the Recaman sequence. This is OEIS A057167. The initial terms that are listed in the OEIS are:

0, 1, 4, 2, 131, 129, 3, 5, 16, 14, 12, 10, 8, 6, 31, 29, 27, 25, 23, 99734, 7, 9, 11, 13, 15, 17, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 111, 22, 20, 18, 28, 30, 32, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196

Notice 99734 that I've marked in red in the terms above. This corresponds to 19 and so a remarkable 99734 iterations are required to reach this modest number. Looking further at the \(b\) table, it can be seen that 61 requires an even more impressive 181653 iterations. Interestingly 76 requires the exact same number of iterations. 133 requires only slightly fewer at 181605 and 223 fewer still at 181545. These "spikes" are relatively infrequent. The next significant one is 879 that requires 328002 iterations. However, these are mere blips compared to the staggering number of iterations required for a number like 2406 (see Table 1).

Also of interest is the maximum number reached in the trajectory leading to a given number. I got Gemini to write a SageMath program that will calculate these two statistics (permalink). Let's say we enter the number 61. Here is the output:

Target Number: 61

Iterations Required: 181653

Highest Value Attained: 881467

I've incorporated this into my daily number analysis. My diurnal age today is 28120 and entering this number, the following output is obtained:

Position in Recaman Sequence:

Target Number: 28120

Iterations Required: 34191

Highest Value Attained: 180120

I also got Gemini to create a graph based on the OEIS A057167 b-table data that lists the number of iterations for the first 20,000 numbers. The program also lists the top ten values in that range. See Figure 1.


Figure 1: permalink

Table 1 shows the top ten in terms of number of iterations required:


Table 1: 
permalink

Sunday, 15 March 2026

There Can Be Only One 1

I've written about \(n\)-free Fibonacci sequences in a post titled Free Fibonacci Sequences, one example of which is the 6-free Fibonacci sequence described as follows:

The sequences of \(n\)-free Fibonacci numbers were suggested by John H. Conway. The 6-free Fibonacci sequence is created by the sum of the two previous terms divided by the largest possible power of 6. The sequence coincides with the Fibonacci sequence until the first multiple of 6 in the Fibonacci sequence: 144, which in this sequence is divided by 36 to produce 4.

The resulting numbers form OEIS A232666 is:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 4, 93, 97, 190, 287, 477, 764, 1241, 2005, 541, 2546, 3087, 5633, 8720, 14353, 23073, 37426, 60499, 97925, 26404

The sequence is base-independent but the "twist" I'm giving to the traditional Fibonacci sequence in this post is base-dependent but it's nonetheless interesting as we'll see. Here is an explanation of what I'm doing. We start with a digit \(d\) between 0 and 9 and any integer \(s\) that does not contain \(d\). For example, \(d=1\) and \(s=2\) would be suitable. After that we begin the Fibonacci process using \(d\) and \(s\) as our seeds except that whenever a number appears containing one or more digits \(d\), they are all removed. A formal definition follows.

Formal Definition of the Digit-Restricted Fibonacci Sequence


Let $d\in\{0,1,2,\dots,9\}$ denote the restricted initial digit, and let $s\in\mathbb{Z}$ denote the arbitrary second initial term. We define a sequence $(a_n)_{n=0}^{\infty}$ generated by a modified second-order linear recurrence, subject to a nonlinear digit-deletion operator.

First, we define the digit-deletion function $\Phi_d:\mathbb{Z}\to\mathbb{Z}$. For any integer $x$, let the absolute value $|x|$ be represented in base-10 as a sequence of digits $C=c_kc_{k-1}\dots c_0$, where $c_i\in\{0,1,\dots,9\}$. Let $C'$ be the subsequence of digits obtained by removing all instances of the forbidden digit $d$ from $C$. The function is defined as:

$$\Phi_d(x)=\begin{cases}0&\text{if }C'\text{ is the empty string},\\\text{sgn}(x)\cdot\text{val}(C')&\text{otherwise},\end{cases}$$

where $\text{sgn}(x)$ represents the sign of $x$, and $\text{val}(C')$ represents the standard base-10 numerical evaluation of the concatenated digit string $C'$.

The sequence $(a_n)$ is then defined recursively by the following initial conditions and recurrence relation:

$$\begin{aligned}a_0&=d,\\a_1&=s,\\a_n&=\Phi_d(a_{n-1}+a_{n-2})\quad\text{for }n\ge 2.\end{aligned}$$


Termination Criteria


To algorithmically generate a finite subsequence
$(a_n)_{n=0}^{N}$, we impose an upper bound constraint $M\in\mathbb{Z}^+$ (with a default of $M=40000$) and a period-detection mechanism. Sequence generation terminates at the index $N$ if either of the following conditions is satisfied:
  1. Threshold Exceedance: The absolute value of the sequence term exceeds the designated maximum bound, such that:

    $$|a_N|>M$$
  2. Loop Detection (Periodicity): The sequence enters a continuous cycle. Because $a_n$ is strictly dependent on the preceding pair $(a_{n-1},a_{n-2})$, periodicity is guaranteed if any consecutive pair repeats. The sequence terminates if there exists an index $k$ such that $1\le k<N-1$ satisfying:

    $$(a_{k-1},a_k)=(a_{N-1},a_N)$$

Upon meeting either termination criterion, the resulting finite sequence $(a_0,a_1,\dots,a_N)$ is yielded.

Figure 1 was the final output which did exactly what I wanted using a "forbidden number" of 1 (thus \(d=1\) ) and a second number of 2 (thus \(s=2\) ). The 34 term sequence generated enters a loop once the terms 5 and 5 are reached with a highest value of 9:

1, 2, 3, 5, 8, 3, 0, 3, 3, 6, 9, 5, 4, 9, 3, 2, 5, 7, 2, 9, 0, 9, 9, 8, 7, 5, 2, 7, 9, 6, 5, 0, 5, 5


Figure 1: permalink

Let's retain 1 as our "forbidden number" (thus \(d=1\) ) and use 24 as the second number (thus \(s=24\) ). Figure 2 shows the result. The 134 term sequence that generated enters a loop once the terms 2 and 8 are reached with a highest value of 98:

1, 24, 25, 49, 74, 23, 97, 20, 7, 27, 34, 6, 40, 46, 86, 32, 8, 40, 48, 88, 36, 24, 60, 84, 44, 28, 72, 0, 72, 72, 44, 6, 50, 56, 6, 62, 68, 30, 98, 28, 26, 54, 80, 34, 4, 38, 42, 80, 22, 2, 24, 26, 50, 76, 26, 2, 28, 30, 58, 88, 46, 34, 80, 4, 84, 88, 72, 60, 32, 92, 24, 6, 30, 36, 66, 2, 68, 70, 38, 8, 46, 54, 0, 54, 54, 8, 62, 70, 32, 2, 34, 36, 70, 6, 76, 82, 58, 40, 98, 38, 36, 74, 0, 74, 74, 48, 22, 70, 92, 62, 54, 6, 60, 66, 26, 92, 8, 0, 8, 8, 6, 4, 0, 4, 4, 8, 2, 0, 2, 2, 4, 6, 0, 6, 6, 2, 8


Figure 2: permalink

This is a rather more interesting graph but the numbers eventually enter a loop. Every time a number exceeds 100, it ends up back under 100. For example:

  • 1, 24, 25, 49, 74, 123 and the 123 becomes 23
  • 23, 97, 120 and the 120 becomes 20
The result is that the maximum value that this 137 term sequence reaches is 98. Let's try 70 as our second number (thus \(d=1\) and \(s=70\) ). Figure 3 shows the result. The resulting 171 term sequence enters a loop once 2 and 8 are reached with a maximum value of 98:

1, 70, 7, 77, 84, 6, 90, 96, 86, 82, 68, 50, 8, 58, 66, 24, 90, 4, 94, 98, 92, 90, 82, 72, 54, 26, 80, 6, 86, 92, 78, 70, 48, 8, 56, 64, 20, 84, 4, 88, 92, 80, 72, 52, 24, 76, 0, 76, 76, 52, 28, 80, 8, 88, 96, 84, 80, 64, 44, 8, 52, 60, 2, 62, 64, 26, 90, 6, 96, 2, 98, 0, 98, 98, 96, 94, 90, 84, 74, 58, 32, 90, 22, 2, 24, 26, 50, 76, 26, 2, 28, 30, 58, 88, 46, 34, 80, 4, 84, 88, 72, 60, 32, 92, 24, 6, 30, 36, 66, 2, 68, 70, 38, 8, 46, 54, 0, 54, 54, 8, 62, 70, 32, 2, 34, 36, 70, 6, 76, 82, 58, 40, 98, 38, 36, 74, 0, 74, 74, 48, 22, 70, 92, 62, 54, 6, 60, 66, 26, 92, 8, 0, 8, 8, 6, 4, 0, 4, 4, 8, 2, 0, 2, 2, 4, 6, 0, 6, 6, 2, 8


Figure 3: permalink

Though this sequence of 171 terms oscillates wildly, it still only reaches a maximum value of 98 before eventually looping. With a forbidden digit of 1 (\(d=1\)) and a starting number that is below 100 (\(s<100\)), no sequence member can exceed 100 and so the sequence must eventually loop.

There's lots to explore here and I'll do that in subsequent posts but that's enough for now. Below the SageMath code is included for completeness.

Updated Python / SageMath Implementation

Python
import matplotlib.pyplot as plt

def custom_fibonacci(forbidden_digit, second_num, max_val=40000):
    """
    Generates a modified Fibonacci sequence where the starting digit is forbidden 
    from appearing in any subsequent terms.
    """
    if not (0 <= forbidden_digit <= 9):
        raise ValueError("The first entry must be a single digit from 0 to 9.")

    sequence = [forbidden_digit, second_num]
    seen_pairs = set()
    seen_pairs.add((forbidden_digit, second_num))
    
    forbidden_str = str(forbidden_digit)
    entered_loop = False

    while True:
        raw_sum = sequence[-2] + sequence[-1]
        sum_str = str(raw_sum)
        filtered_str = sum_str.replace(forbidden_str, '')
        
        if filtered_str == '' or filtered_str == '-':
            next_term = 0
        else:
            next_term = int(filtered_str)
            
        if next_term > max_val:
            break
            
        current_pair = (sequence[-1], next_term)
        if current_pair in seen_pairs:
            entered_loop = True
            break
            
        sequence.append(next_term)
        seen_pairs.add(current_pair)

    return sequence, entered_loop

def plot_trajectory(sequence, forbidden_digit, second_num):
    """
    Plots the sequence trajectory with thin black lines, small black circles,
    and dynamic headroom to prevent annotation overlap with the title.
    """
    plt.figure(figsize=(12, 6))
    
    # Plot with thin black lines and small black circles
    plt.plot(sequence, color='black', marker='o', markersize=4, linewidth=1, linestyle='-')
    
    # Find and annotate the maximum value
    max_val = max(sequence)
    max_index = sequence.index(max_val)
    
    # Dynamically expand the y-axis to create headroom for the annotation
    plt.ylim(bottom=min(sequence) - (max_val * 0.05), top=max_val * 1.15)
    
    plt.annotate(f'Max Value Reached: {max_val}', 
                 xy=(max_index, max_val), 
                 xytext=(0, 15), # Offsets the text 15 points above the point
                 textcoords='offset points',
                 ha='center', 
                 va='bottom',
                 bbox=dict(boxstyle='round,pad=0.3', fc='white', ec='gray', lw=0.5),
                 arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0', color='black'))

    # Formatting the graph with added title padding
    plt.title(f"Modified Fibonacci Trajectory\nForbidden Digit: {forbidden_digit} 
| Starting Number: {second_num}", pad=20)
    plt.xlabel("Sequence Index (Term Number)")
    plt.ylabel("Value")
    plt.grid(True, linestyle='--', alpha=0.5)
    
    plt.tight_layout()
    plt.show()

# --- Execution and Display ---

digit_1 = 1
digit_2 = 2
max_limit = 40000

result_sequence, is_loop = custom_fibonacci(digit_1, digit_2, max_val=max_limit)

# 1. Print Text Output First
print(f"Starting Parameters: Forbidden Digit = {digit_1}, Second Number = {digit_2}")
print(f"Max Value Limit: {max_limit}")
print("-" * 50)
print(f"Resulting Sequence ({len(result_sequence)} terms):")
print(result_sequence)
print("-" * 50)

if is_loop:
    print("Conclusion: The sequence entered a continuous loop.")
    print(f"The repeating pair that triggered the stop was: 
({result_sequence[-2]}, {result_sequence[-1]})")
else:
    print(f"Conclusion: The sequence stopped because a term exceeded {max_limit}.")

# 2. Render Graph Below
plot_trajectory(result_sequence, digit_1, digit_2)