login
A397083
Start with a(1) = 2; to get a(n+1) insert in a(n) at the leftmost possible position the smallest possible digit such that the new number is a prime.
2
2, 23, 223, 1223, 31223, 231223, 6231223, 61231223, 661231223, 5661231223, 56161231223, 526161231223, 5216161231223, 25216161231223, 425216161231223, 6425216161231223, 66425216161231223, 664325216161231223, 9664325216161231223, 29664325216161231223, 296764325216161231223, 2996764325216161231223
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
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.
Sequence in context: A242904 A068167 A030456 * A397084 A357436 A069837
KEYWORD
nonn,base
AUTHOR
Bartlomiej Pawlik, Jun 16 2026
STATUS
approved