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.

A377090 a(0) = 0; thereafter, for n > 0, a(n) is the least integer (in absolute value) not yet in the sequence such that the absolute difference between a(n-1) and a(n) is a prime number; in case of a tie, preference is given to the positive value.

Original entry on oeis.org

0, 2, -1, 1, -2, 3, -4, -6, -3, 4, 6, -5, -7, -9, 8, 5, 7, 9, -8, -10, -12, 11, 13, 10, 12, -11, -13, -15, 14, 16, 18, 15, -14, -16, -18, 19, 17, 20, -17, -19, -21, 22, 24, 21, -20, -22, -24, 23, 25, 27, -26, -23, -25, -27, 26, 28, 30, -29, -31, -28, -30, 29
Offset: 0

Views

Author

Rémy Sigrist, Oct 16 2024

Keywords

Comments

This sequence is a variant of A277618 allowing negative values.
Will every integer appear in the sequence?
Conjecture (after studying A383445 and A383446): The sequence contains every integer. - N. J. A. Sloane, Apr 30 2025
The distances d(n) = |a(n)| - n/2 remain very small. Records values of |d(n)| appear at d(1) = 1.5, d(7) = 2.5, d(30) = 3.0, d(117) = 3.5, d(124) = -4.0, d(326) = -5.0, d(530) = 6.0, d(1137) = 6.5, d(1142) = -7.0, d(1342) = 8.0, d(5363) = 8.5, d(5370) = -9.0, d(9567) = 9.5, d(9568) = 10.0, ... - M. F. Hasler, Feb 10 2025

Examples

			The first terms are:
   n   a(n)  |a(n)-a(n-1)|
  --- ------ -------------
   0     0        N/A
   1     2         2
   2    -1         3
   3     1         2
   4    -2         3
   5     3         5
   6    -4         7
   7    -6         2
   8    -3         3
   9     4         7
  10     6         2
  11    -5        11
  12    -7         2
  13    -9         2
  14     8        17
		

Crossrefs

Cf. A277618, A377091, A377092, A380311 (partial sums), A383444 (differences), A383445, A383446.

Programs

  • Mathematica
    A377090list[nmax_] := Module[{s, a, u = 1}, s[_] := False; s[0] = True; NestList[(While[s[u] && s[-u], u++]; a = u; While[s[a] || !PrimeQ[Abs[# - a]], a = Boole[a < 0] - a]; s[a] = True; a) &, 0,nmax]];
    A377090list[100] (* Paolo Xausa, Mar 27 2025 *)
  • PARI
    \\ See Links section.
    
  • PARI
    A377090_first(N, L=1, U=[])={vector(N, n, while(setsearch(U,L), U=setminus(U,[L]); L=(L<0)-L); N=if(n>1, n=L; while(!isprime(abs(n-N)) || setsearch(U, n), n=(n<0)-n); U=setunion(U, [n]); n))} \\ M. F. Hasler, Feb 21 2025
    
  • Python
    from sympy import isprime
    from itertools import count, islice
    def cond(n): return isprime(n)
    def agen(): # generator of terms
        an, aset, m = 0, {0}, 1
        for n in count(0):
            yield an
            an = next(s for k in count(m) for s in [k, -k] if s not in aset and cond(abs(an-s)))
            aset.add(an)
            while m in aset and -m in aset: m += 1
    print(list(islice(agen(), 62))) # Michael S. Branicky, Dec 27 2024
    
  • Python
    from sympy import isprime
    def A377090(n):
        while len(terms := A377090.terms) <= n:
            while (k := A377090.N) in terms: A377090.N = (k<0)-k
            while not isprime(abs(k - terms[-1])) or k in terms: k = (k<0)-k
            terms.append(k)
        return terms[n]
    A377090.terms = [0]; A377090.N = 1 # least unused candidate
    # M. F. Hasler, Feb 10 2025, simplified Feb 15 2025

Formula

||a(n)| - n/2| = O(log(n)), probably ||a(n)| - n/2| < 2 log(n+2) for all n. (Conjectured; verified up to n = 10^5.) - M. F. Hasler, Feb 21 2025