cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A356557 Start with a(1)=2; to get a(n+1) insert in a(n) at the rightmost possible position the smallest possible digit such that the new number is a prime.

Original entry on oeis.org

2, 23, 233, 2333, 23333, 233323, 2333231, 23332301, 233323001, 2333230019, 23332030019, 233320360019, 2333203600159, 23332036001959, 233320360019569, 2333203600195669, 23332036001956469, 233320360019564269, 2333203600195642469, 23332036001956424629, 233320360019564246269
Offset: 1

Views

Author

Bartlomiej Pawlik, Aug 12 2022

Keywords

Comments

Extending a number by inserting a prepending "0" is obviously not allowed. Rightmostness of position has precedence over smallness of digit. If no prime extension exists, the sequence terminates.
Sequence inspired by A332603.
Sequence construction very similar to A357436 (the difference arises from the order of the conditions).
Length of a(n) is n.
Is the sequence infinite? The analogous sequences using bases 2, 3, 4, 5 and 7 are finite.
Sequence terminates if and only if it contains a term of A125001.

Examples

			a(2) = 23 because the numbers 20, 21, 22 obtained from a(1) = 2 are composite and 23 is a prime.
For n=6, starting from a(5)=23333 and appending a new rightmost digit gives 233330, 233331, ..., 233339 which are not primes. Inserting a digit second-rightmost gives 233303 and 233313 which are also not prime, and 233323 which is prime, so a(6) = 233323.
		

Crossrefs

Programs

  • Mathematica
    k = 2; K = {k}; For[n = 1, n <= 20, n++, r = 0; For[p = IntegerLength[k] + 1, p >= 1, p--, If[r == 1, Break[]]; For[d = 0, d <= 9, d++, If[PrimeQ[ m = ToExpression[StringInsert[ToString[k], ToString[d], p]]], If[k != m, k = m, Print["FINITE"]]; AppendTo[K, k]; r = 1; Break[]]]]]; Print[K] (* Samuel Harkness, Sep 29 2022 *)
  • 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":
                w = s + c if k == 0 else 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(), 21))) # Michael S. Branicky, Aug 12 2022