A357436 Start with a(1)=2; to get a(n+1) insert in a(n) the smallest possible digit at the rightmost possible position such that the new number is a prime.
2, 23, 223, 2203, 22003, 220013, 2200103, 22000103, 223000103, 2230001003, 22300010023, 223000100023, 2230001000203, 22301001000203, 223010001000203, 2230010001000203, 22300010001000203, 222300010001000203, 2223000100010001203, 22203000100010001203, 222030001000010001203, 2220300010200010001203
Offset: 1
Examples
a(2) = 23 because the numbers 20, 21, 12, 22 obtained from a(1) = 2 are composite and 23 is a prime. For n=6, starting from a(5)=22003 and appending a digit "0" from right to left gives 220030, 220003, 202003, which are not primes. Inserting a digit "1" from right to left gives 220031 which also is not prime, and 220013 which is prime, so a(6) = 220013.
Links
- Michael S. Branicky, Table of n, a(n) for n = 1..1000
Programs
-
Maple
f:= proc(n) local x, y,z, j; for x from 0 to 9 do for j from 0 to length(n)-`if`(x=0,1,0) do y:= n mod 10^j; z:= y + x*10^j + 10*(n-y); if isprime(z) then return z fi; od od; FAIL end proc: R:= 2: x:= 2: for count from 2 to 30 while x <> FAIL do x:= f(x); R:= R, x; od: R; # Robert Israel, Sep 29 2022
-
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 + Length@ d}]]; Array[a, 22] (* Giovanni Resta, Oct 13 2022 *)
-
Python
from sympy import isprime from itertools import islice def anext(an): s = str(an) for c in "0123456789": for k in range(len(s)+1): w = s + c if k == 0 else s[:-k] + c + s[-k:] if w[0] != "0" and 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, Sep 29 2022
Extensions
More terms from Robert Israel, Sep 29 2022
Comments