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.

A255004 Lexicographically earliest permutation of positive integers such that a(a(n)+a(n+1)) is prime for all n.

Original entry on oeis.org

1, 2, 3, 4, 5, 6, 7, 8, 11, 9, 13, 10, 17, 12, 19, 14, 15, 16, 23, 29, 18, 31, 37, 20, 21, 22, 41, 24, 43, 25, 47, 26, 53, 27, 28, 30, 32, 33, 59, 34, 61, 35, 67, 36, 38, 39, 71, 40, 73, 42, 44, 79, 45, 46, 83, 48, 89, 97, 49, 50, 51, 101, 103, 52, 107, 54
Offset: 1

Views

Author

Eric Angelini and M. F. Hasler, Feb 11 2015

Keywords

Comments

This is the sequence V defined in the Comments on A255003.

Crossrefs

For indices of primes see A256212.

Programs

  • Maple
    N:= 100: # to get a(n) for n <= N
    maxprime:= 2:
    maxa:= 2:
    a[1]:= 1:
    a[2]:= 2:
    needprime:= {3}:
    for n from 3 to N do
      if member(n,needprime) then
         a[n]:= nextprime(maxprime);
         maxprime:= a[n];
      else
         if isprime(maxa+1) and maxa+1<= maxprime then a[n]:= maxa+2
         else a[n]:= maxa+1
         fi;
         maxa:= a[n];
      fi;
      needprime:= needprime union {a[n-1]+a[n]};
    od:
    seq(a[n],n=1..N); # Robert Israel, Mar 26 2015
  • Mathematica
    M = 100;
    maxprime = 2; maxa = 2; a[1] = 1; a[2] = 2; needprime = {3}; For[n = 3, n <= M, n++, If[MemberQ[needprime, n], a[n] = NextPrime[maxprime]; maxprime = a[n], If[PrimeQ[maxa+1] && maxa+1 <= maxprime, a[n] = maxa+2, a[n] = maxa+1]; maxa = a[n]]; needprime = needprime ~Union~ {a[n-1] + a[n]}];
    Array[a, M] (* Jean-François Alcover, Mar 22 2019, after Robert Israel *)
  • PARI
    {a=vector(100,i,1); u=[1]/* used numbers beyond u[1] */; for(n=2,#a, if( a[n] < 0, a[n]=u[1]; while(setsearch(u,a[n]++)||!isprime(a[n]),), a[n]=u[1]; while(setsearch(u,a[n]++),)); u=setunion(u,[a[n]]); while( #u>1 && u[2]==u[1]+1, u=u[2..#u]); a[n]+a[n-1]>#a || a[a[n]+a[n-1]]=-1)}