OFFSET
1,1
COMMENTS
This is the left-right counterpart of A356557. It uses the same precedence of the insertion position over smallness of the inserted digit, but considers positions from left to right instead of from right to left.
Together with A356557, A357436, and A397084, 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.
Leftmostness of the insertion position has precedence over smallness of the inserted digit.
Prepending a digit 0 is not allowed.
If no prime extension exists, the sequence terminates.
The number 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(3) = 223. Starting from 23, the leftmost position is checked first. Prepending 1 gives 123, which is composite, while prepending 2 gives the prime 223.
a(8) = 61231223. Starting from 6231223, no prepended digit produces a prime. At the second insertion position, inserting 1 gives the prime 61231223.
MATHEMATICA
a[1]=2; a[n_]:=a[n]=Catch@Module[{digits=IntegerDigits[a[n - 1]], candidate},
Do[If[position == 1 && digit == 0, Continue[]]; candidate = FromDigits@Insert[digits, digit, position]; If[PrimeQ[candidate], Throw[candidate]], {position, 1, Length[digits] + 1}, {digit, 0, 9}]]; Array[a, 22]
PROG
(Python)
from sympy import isprime
from itertools import islice
def anext(an):
s = str(an)
for k in range(len(s)+1):
for c in "0123456789"[int(k==0):]:
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. A356557, the right-to-left counterpart, in which the insertion position also has precedence over smallness of the inserted digit.
Cf. A397084, which also considers insertion positions from left to right, but gives precedence to smallness of the inserted digit over leftmostness of position.
Cf. A357436, in which smallness of the inserted digit has precedence and insertion positions are considered from right to left.
KEYWORD
nonn,base
AUTHOR
Bartlomiej Pawlik, Jun 16 2026
STATUS
approved
