Showing posts with label digit. Show all posts
Showing posts with label digit. Show all posts

Monday, 3 August 2026

Semiprimes Within Semiprimes

I got to thinking about semiprimes and how many of them have the property that the digits of their two prime factors can both be rearranged to form two new semiprimes. It's as if two additional semiprimes are hiding within the factors of the original semiprime.

It's simple enough to investigate and I could have written the code but I lazily got Gemini to do it for me. It turns out that there are 1077 such numbers in the range up to 40000 (permalink). the first such number is 361:$$ \begin{align} 361 &=19 \times 19 \\19 &\rightarrow 91 =7 \times 13 \end{align}$$The next such number is not square and is 779:$$ \begin{align} 779 &= 19 \times 41 \\ 19 &\rightarrow 91 =7 \times 13 \\ 41 &\rightarrow 14 =2 \times 7 \end{align}$$Here is a list of the numbers from 28247 (my diurnal age tomorrow) up to 40000:

28247, 28253, 28261, 28291, 28331, 28337, 28367, 28417, 28423, 28459, 28481, 28529, 28667, 28673, 28709, 28733, 28757, 28801, 28811, 28841, 28891, 28907, 28937, 28939, 28943, 28967, 28969, 28991, 28999, 29083, 29089, 29093, 29111, 29143, 29149, 29177, 29299, 29317, 29321, 29329, 29353, 29369, 29431, 29441, 29479, 29503, 29507, 29521, 29539, 29591, 29621, 29657, 29677, 29713, 29747, 29773, 29797, 29839, 29849, 29893, 29929, 29987, 30001, 30031, 30077, 30127, 30157, 30179, 30221, 30227, 30263, 30299, 30301, 30343, 30353, 30409, 30461, 30463, 30533, 30571, 30607, 30629, 30647, 30691, 30739, 30761, 30791, 30799, 30847, 30857, 30913, 30917, 30929, 30967, 30973, 31067, 31103, 31111, 31133, 31201, 31313, 31373, 31429, 31439, 31457, 31459, 31483, 31529, 31597, 31621, 31631, 31673, 31693, 31711, 31747, 31777, 31819, 31831, 31853, 31861, 31877, 31897, 31919, 31921, 31937, 31949, 32041, 32101, 32111, 32167, 32171, 32231, 32239, 32243, 32267, 32273, 32281, 32287, 32293, 32387, 32399, 32471, 32477, 32489, 32639, 32651, 32677, 32699, 32701, 32723, 32737, 32743, 32761, 32807, 32863, 32899, 32927, 32951, 33017, 33043, 33067, 33079, 33127, 33193, 33217, 33221, 33239, 33251, 33307, 33389, 33401, 33421, 33443, 33463, 33499, 33571, 33661, 33689, 33743, 33763, 33793, 33841, 33877, 33907, 33953, 33973, 33989, 33991, 34079, 34081, 34093, 34117, 34121, 34163, 34189, 34219, 34271, 34291, 34387, 34393, 34399, 34417, 34547, 34553, 34571, 34579, 34609, 34633, 34637, 34717, 34733, 34777, 34789, 34873, 34889, 34921, 34927, 34933, 34943, 34973, 34987, 35033, 35093, 35137, 35183, 35209, 35219, 35237, 35263, 35297, 35303, 35341, 35359, 35383, 35389, 35459, 35473, 35549, 35561, 35587, 35611, 35647, 35657, 35663, 35669, 35687, 35701, 35723, 35741, 35767, 35773, 35813, 35881, 35891, 35909, 35939, 35941, 35947, 35953, 35957, 36031, 36077, 36079, 36089, 36119, 36121, 36143, 36167, 36199, 36203, 36233, 36331, 36347, 36359, 36367, 36391, 36403, 36437, 36481, 36503, 36521, 36557, 36581, 36623, 36679, 36689, 36727, 36851, 36853, 36863, 36937, 36977, 36989, 37031, 37069, 37109, 37127, 37211, 37229, 37249, 37327, 37351, 37391, 37399, 37459, 37487, 37523, 37601, 37627, 37669, 37711, 37753, 37769, 37801, 37819, 37823, 37837, 37867, 37883, 37901, 37931, 37937, 37943, 37969, 37979, 37981, 38021, 38041, 38089, 38107, 38117, 38141, 38173, 38191, 38209, 38243, 38263, 38293, 38323, 38417, 38429, 38477, 38497, 38513, 38527, 38551, 38581, 38587, 38681, 38741, 38761, 38771, 38807, 38809, 38827, 38869, 38881, 38911, 38957, 38963, 38989, 38999, 39007, 39037, 39059, 39073, 39131, 39167, 39173, 39187, 39197, 39283, 39311, 39337, 39379, 39407, 39433, 39539, 39577, 39617, 39647, 39653, 39691, 39707, 39713, 39751, 39757, 39803, 39811, 39881, 39913, 39943, 39947

It was quite serendipitous that I thought about these sorts of numbers because, as I said, I'm 28247 days old tomorrow and this number has the property that:$$ \begin{align} 28247 &= 47 \times 601 \\47 &\rightarrow 74 =2 \times 37 \\ 601 &\rightarrow 106 =2 \times 53 \end{align}$$From my previous examples, it might look as if the two factors are having their digits reversed but remember the digits are being rearranged and not necessarily reversed. Take 28253 as an example:$$ \begin{align} 28253 &= 19 \times 1487 \\ 19 &\rightarrow 91=7 \times 13\\ 1487 &\rightarrow 7841 \text{ which is prime} \\1487 &\rightarrow 7814 = 2 \times 3907 \end{align}$$Of course this idea can be extended to sphenic numbers where each the three factors have digits that can be rearranged to form three new sphenic numbers. However, these numbers are comparatively speaking rather large. The first is 1113121 (permalink):$$ \begin{align} 1113121 &= 101 \times 103 \times 107 \\ 101&\rightarrow 110 =2 \times 5 \times 11 \\ 103 &\rightarrow 130 =2 \times 5 \times 13 \\ 107 &\rightarrow 170 = 2 \times 5 \times 17 \end{align}$$Gemini gives a good explanation of why the numbers need to be so large (link).

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:

Tuesday, 24 March 2026

Digit Manipulation


Video created by NotebookLM based on blog content

DIGITS TO SQUARES

Yesterday I turned 28113 days old and this number is a member of OEIS A048383: numbers \(k\) such that replacing each nonzero digit \(d\) with the \(d\)-th prime (replacing each 0 digit with a 1) yields a square. So this means that:$$28113 \rightarrow 319225 = 5^2 \times 113^2$$The members of this sequence are few and far between and in the range up to 40000 only the following numbers satisfy (permalink):$$ \begin{align} 0 &\rightarrow 1 = 1\\13 &\rightarrow 25 = 5^2\\113 &\rightarrow 225 = 3^2 \times 5^2\\2410 &\rightarrow 3721 = 61^2\\4113 &\rightarrow 7225 = 5^2 \times 17^2\\6113 &\rightarrow 13225 = 5^2 \times 23^2\\8210 &\rightarrow 19321 = 139^2\\14113 &\rightarrow 27225 = 3^2 \times 5^2 \times 11^2\\23410 &\rightarrow 35721 = 3^6 \times 7^2\\28113 &\rightarrow 319225 = 5^2 \times 113^2\\33113 &\rightarrow 55225 = 5^2 \times 47^2\\34010 &\rightarrow 57121 = 239^2\\35113 &\rightarrow 511225 = 5^2 \times 11^2 \times 13^2\\\end{align}$$DIGITS TO PRIMES

A variation on this theme is OEIS A048381:


A048381: numbers \(k\) such that replacing each nonzero digit \(d\) with the \(d\)-th prime (replacing each 0 digit with a 1) yields a prime.

Members of this sequence are far more numerous with 5629 in the range up to 40000. An example is 28112 since:$$28112 \rightarrow 319223 \text{ which is prime} $$Some upcoming members are:

28124, 28146, 28152, 28155, 28202, 28210, 28214, 28216, 28226, 28228, 28230, 28234, 28235, 28236, 28247, 28265, 28270, 28277, 28289, 28294, 28295, 28298, 28300, 28317, 28319, 28328, 28329, 28344, 28359, 28360, 28368, 28388, 28392, 28397, 28414, 28418, 28422, 28429, 28434, 28449, 28458, 28464, 28470, 28474, 28485, 28490, 28498, 28502, 28504, 28515, 28524, 28525, 28529, 28546, 28562, 28575, 28592, 28599, 28606, 28612, 28614, 28622, 28630, 28652, 28658, 28665, 28667, 28674, 28684, 28686, 28706, 28717, 28724, 28744, 28752, 28772, 28786, 28807, 28810, 28814, 28825, 28827, 28838, 28854, 28868, 28870, 28876, 28886, 28888, 28890, 28928, 28929, 28932, 28948, 28955, 28960, 28966, 28979, 28984, 28988, 28995, 28997

One way to thin the numbers when there are so many in a given range is to require that the numbers come in pairs that are consecutive integers. If this requirement is imposed then the 5629 reduces to 580. Imposing the restriction that the numbers are triplets that are consecutive integers reduces the 580 further to a manageable 103:

1, 2, 3, 4, 5, 6, 7, 24, 25, 144, 166, 167, 414, 474, 506, 674, 897, 898, 1026, 1027, 1176, 1177, 1398, 1516, 1824, 2035, 2074, 2094, 2146, 2544, 3316, 4044, 5247, 5248, 5286, 5514, 6044, 6484, 7116, 7117, 7118, 7264, 7918, 8008, 8127, 8444, 8665, 10016, 11046, 11047, 11404, 13068, 13445, 14224, 14584, 15886, 16055, 16346, 16347, 16505, 16945, 18306, 18497, 19276, 19465, 20044, 20124, 21797, 21798, 22167, 22416, 22417, 22586, 22694, 22767, 23336, 23774, 24726, 24727, 24845, 25934, 26608, 26844, 26885, 28234, 29376, 29377, 29714, 29715, 29917, 30145, 30705, 32244, 32248, 33807, 35405, 35647, 36018, 36635, 37888, 38097, 39067, 39527

Let's take 28234 as an example where:$$ \begin{align} 28234 &\rightarrow 319357\\28235 &\rightarrow 3193511\\28236 &\rightarrow 3193513 \end{align}$$There is of course an initial run of seven numbers (1 to 7) and after that there are runs of four numbers beginning with:

24, 166, 897, 1026, 1176, 5247, 7116, 7117, 11046, 16346, 21797, 22416, 24726, 29376, 29714

Finally there is only one run of five numbers and it starts with 7116.

DIGITS TO PALINDROMES

Another variation, using this same method of digit manipulation, is to ask what non-palindromic number become palindromes. Well, in the range up to 40000, it turns out that 333 numbers satisfy this condition (permalink). The numbers from 28113 onwards are:

28086, 28586, 28686, 28786, 28802, 28886, 29029, 29069, 29129, 29199, 29212, 29229, 29329, 29429, 29529, 29569, 29612, 29669, 29769, 29869, 29912, 29999, 30053, 30553, 30653, 30753, 30853, 32063, 32193, 32563, 32663, 32763, 32863, 32993, 34073, 34573, 34673, 34773, 34873, 35003, 35503, 36203, 36603, 36903, 37403, 37703, 38803, 39213, 39613, 39913

Let's use 28086 as an example:$$28086 \rightarrow 31911913$$Clearly there are many possible variations using just this particular type of digit manipulation and in this post I've shown examples of three of them where the digits \(d\) are manipulated as follows:$$ \begin{align} d &\rightarrow \text{ prime}(d) \text{ if } d \neq 0 \\0 &\rightarrow 1 \end{align} $$However, other manipulations are limited only by your imagination. An example of different type of manipulation would be:$$ d \rightarrow d^{ \, \small{2}}$$We can ask how many non-palindromic numbers become palindromes when their digits are manipulated in this manner (squared). In the range up to 40000, the answer is that there are 96 suitable numbers and they are (permalink):

19, 28, 37, 41, 72, 199, 288, 327, 377, 441, 461, 732, 772, 1191, 1281, 1371, 1411, 1721, 1919, 1999, 2192, 2282, 2372, 2412, 2722, 2828, 2888, 3193, 3207, 3217, 3227, 3237, 3283, 3373, 3413, 3723, 3737, 3777, 4141, 4441, 4661, 7032, 7132, 7232, 7272, 7332, 7772, 11991, 12881, 13271, 13771, 14411, 14611, 17321, 17721, 19019, 19119, 19219, 19319, 19999, 21992, 22882, 23272, 23772, 24412, 24612, 27322, 27722, 28028, 28128, 28228, 28328, 28888, 31993, 32007, 32117, 32197, 32227, 32287, 32337, 32377, 32417, 32727, 32883, 33273, 33773, 34413, 34613, 37037, 37137, 37237, 37277, 37323, 37337, 37723, 37777

An example is 28028 where$$28028 \rightarrow 4640464$$

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)