OFFSET
1,1
COMMENTS
This is the left-right counterpart of A357436. It uses the same precedence of smallness of the inserted digit over the insertion position, but considers positions from left to right instead of from right to left.
Together with A356557, A357436, and A397083, this sequence belongs to the family obtained by choosing the precedence between digit smallness and insertion position, and the direction in which insertion positions are considered.
Smallness of the inserted digit has precedence over leftmostness of its position.
Prepending a 0 is not allowed.
If no prime extension exists, the sequence terminates.
a(n) has n decimal digits.
The sequence terminates if and only if it contains a term of A125001.
Is the sequence infinite?
LINKS
Michael S. Branicky, Table of n, a(n) for n = 1..1000
EXAMPLE
a(2) = 23. Starting from a(1) = 2, insertion positions are considered from left to right for each digit. The numbers 20, 21, 22 are composite, while 23 is prime.
a(7) = 2200013. Starting from a(6) = 220013, insertion of the digit 0 is tested from left to right. Prepending 0 is not allowed; 2020013 is composite, while 2200013 is prime.
MATHEMATICA
a[1]=2; a[n_]:=a[n]=Catch@Block[{p, d = IntegerDigits[a[n - 1]]}, Do[p=FromDigits@Insert[d, c, i]; If[p>a[n-1]&&PrimeQ[p], Throw[p]], {c, 0, 9}, {i, 1, 1+Length[d]}]]; Array[a, 22]
PROG
(Python)
from sympy import isprime
from itertools import islice
def anext(an):
s = str(an)
for c in "0123456789":
for k in range(int(c=="0"), len(s)+1):
w = s[:k] + c + s[k:]
if isprime(int(w)): return int(w)
def agen(an=2):
while an != None: yield an; an = anext(an)
print(list(islice(agen(), 22))) # Michael S. Branicky, Jun 16 2026
CROSSREFS
Cf. A357436, the right-to-left counterpart, in which smallness of the inserted digit also has precedence over the insertion position.
Cf. A397083, which also considers insertion positions from left to right, but gives precedence to leftmostness of position over smallness of the inserted digit.
Cf. A356557, in which rightmostness of position has precedence over smallness of the inserted digit.
KEYWORD
nonn,base
AUTHOR
Bartlomiej Pawlik, Jun 16 2026
STATUS
approved
