login
A389824
a(1) = 1; for n > 1, a(n) is the smallest unused prime number that can be created by either removing or adding a single digit anywhere in the value of a(n-1).
8
1, 11, 101, 1013, 13, 3, 23, 2, 29, 229, 1229, 12239, 1223, 223, 2203, 12203, 102203, 10223, 102023, 1020023, 20023, 2003, 20063, 2063, 263, 2633, 233, 2333, 20333, 203233, 20233, 120233, 1020233, 102233, 1022033, 122033, 1220333, 220333, 2203133, 223133
OFFSET
1,2
COMMENTS
On removing the leading digit, any subsequent leading zeros are also removed.
The sequence is finite, the final term being a(17608) = 10253452803799, after which all digit removals or additions to 10253452803799 lead to composites or primes that already appear in the sequence.
The largest term is a(9551) = 100000000000206050030346930504857.
The list of missing primes begins 7, 17, 19, 31, 37, 41, 43, 47, 61, ... .
See A389825 for the sequence starting at 2.
LINKS
EXAMPLE
a(10) = 229 as a(9) = 29, and the primes created from removing a single digit from 29 are 2, which has been used, while the primes created from adding a single digit to 29 are 229, 829, 929, 239, 269, 293. Of those 229 is the smallest and is therefore the next term chosen.
PROG
(Python)
from gmpy2 import is_prime
from itertools import islice
def agen(): # generator of terms
an, aset = 1, {1}
while an != -1:
yield an
aset.add(an)
s = str(an)
D = set(p for i in range(len(s)) if len(t:=s[:i]+s[i+1:]) and is_prime(p:=int(t)))
if D and (Dcands:=D-aset):
an = min(D - aset)
continue
A = set(p for i in range(len(s)+1) for d in "0123456789" if is_prime(p:=int(s[:i]+d+s[i:])))
an = min(Acands) if A and (Acands:=A-aset) else -1
print(f"Last term is a({len(aset)}).")
print(list(islice(agen(), 40))) # Michael S. Branicky, Oct 19 2025
CROSSREFS
Cf. A389825 (start at 2), A000040, A080603, A080608, A068166.
Sequence in context: A289466 A289532 A288826 * A068166 A199306 A282958
KEYWORD
nonn,fini,full,base
AUTHOR
Scott R. Shannon, Oct 16 2025
STATUS
approved