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.

A111382 Beginning with 3, least number such that concatenation of first n terms and its digit reversal both are primes.

Original entry on oeis.org

3, 1, 1, 21, 11, 43, 47, 157, 753, 51, 917, 273, 2409, 703, 413, 3729, 1153, 6243, 8789, 2307, 4477, 137, 403, 10649, 4617, 4533, 6133, 4721, 877, 2469, 5967, 1557, 1047, 38931, 15533, 6877, 23987, 4767, 18049, 1463, 118333, 27897
Offset: 1

Views

Author

Hans Havermann, Nov 08 2005

Keywords

Crossrefs

Cf. A113584.

Programs

  • Maple
    rev:= proc(n) local L,i;
      L:= convert(n,base,10);
      add(L[-i]*10^(i-1),i=1..nops(L))
    end proc;
    R:= 3: X:= 3: XR:= 3:
    for i from 2 to 50 do
      for x from 1 by 2 do
        d:= 1+ilog10(x);
        t:= X*10^(1+ilog10(x)) + x;
        if not isprime(t) then next fi;
        xr:= rev(x);
        tr:= XR+xr*10^(1+ilog10(XR));
        if isprime(tr) then break fi;
      od;
      X:= t; XR:= tr; R:= R,x;
    od:
    R; # Robert Israel, Aug 09 2023
  • Python
    from itertools import count, islice
    from gmpy2 import digits, is_prime, mpz
    def agen(): # generator of terms
        s, r, an = "", "", 3
        while True:
            yield int(an)
            d = digits(an)
            s, r, k, sk = s+d, d[::-1]+r, 1, "1"
            while not is_prime(mpz(s+sk)) or not is_prime(mpz(sk[::-1]+r)):
                k += 2
                if k%10 == 5: k += 2
                sk = digits(k)
            an = k
    print(list(islice(agen(), 42))) # Michael S. Branicky, Jan 02 2025