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.

A382482 a(1) = 1. Let a(n) be the most recently defined term. At each step, check for an undefined term with index < n. If such a term exists, then where i is the earliest such index, set a(i) = a(n) - (n - i). If no such term exists, then where i is the first undefined index >= n + a(n), set a(i) = the smallest integer not yet used.

Original entry on oeis.org

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

Views

Author

Sameer Khan, Mar 28 2025

Keywords

Comments

The sequence starts at 1 and is defined by two alternating rules:
(1) Where there are undefined terms that appear earlier in the sequence than the most recently defined term, populate the earliest undefined term by taking the most recently defined term and subtracting the difference between their indexes.
(2) Otherwise, move ahead a distance equal to the value of the most recently defined term and populate the first undefined term on or after that index with the smallest unused positive integer.
The sequence calculates terms in a non-sequential order, and so the n-th term of the sequence is generally not the n-th term to be calculated.
The sequence is infinite, but for any calculated length greater than nine terms (1, 2, 2, 3, 4, 2, 5, 6, 5), there will be undefined terms occurring before further defined terms; the sequence leaves gaps as part of its generation. These gaps will eventually get filled if generation continues, although new gaps will always exist.
The scatter plot is of interest, especially when looking at the first 1000 to 2000 terms. There are two distinct lines from the origin (illustrating the back filling and forward jumping nature of the sequence), but each of these lines occasionally splits into two separate lines before converging again, in a non-uniform manner and unrelated to each other.

Examples

			In the examples, missing terms are denoted by the "_" character and the most recently defined term is denoted as a(n).
Starting at n = 1 and a(1) = 1, the next n is therefore 1 + 1 = 2, with a(2) = 2 (the smallest unused positive integer):
n    1 2
a(n) 1 2
There are no missing terms, so using n = 2 and a(2) = 2, the next n is 2 + 2 = 4, with a(4) = 3:
n    1 2 3 4
a(n) 1 2 _ 3
There is now a single missing term at index 3, so that is the next n. It is 1 step back from the previous n, so a(3) = 3 - 1 = 2.
n    1 2 3 4
a(n) 1 2 2 3
There are no missing terms, so using n = 3 and a(3) = 2, the next n is 3 + 2 = 5, with a(5) = 4:
n    1 2 3 4 5
a(n) 1 2 2 3 4
There are no missing terms, so using n = 5 and a(5) = 4, the next n is 5 + 4 = 9, with a(9) = 5:
n    1 2 3 4 5 6 7 8 9
a(n) 1 2 2 3 4 _ _ _ 5
There are now missing terms, the earliest of which being at index 6, so that is the next n. It is 3 steps back from the previous n, so a(6) = 5 - 3 = 2:
n    1 2 3 4 5 6 7 8 9
a(n) 1 2 2 3 4 2 _ _ 5
		

Programs

  • Python
    requiredTerms = 100
    sequence = [None] * (requiredTerms*2)
    k,v = 0,1
    max = 0
    while True:
        sequence[k] = v
        if (v > max):
            max = v
        u = sequence.index(None)
        if u >= requiredTerms:
            break
        elif u < k:
            # advance backward, and decrement v by that much too
            d = k - u
            (k, v) = (k - d, v - d)
        else:
            # skip forward v, then advance to the next unfilled position
            (k, v) = (sequence.index(None, k + v), max + 1)
    for result in range(requiredTerms):
        print(sequence[result])