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.

A337980 When terms first appear in the sequence they are "untouched". Start with a(1)=1. Thereafter, to find a(n), let k = a(n-1). If there is an earlier occurrence a(n-m) = k which is untouched, then a(n) = m and a(n-m) is now "touched". Otherwise, a(n) = 0.

Original entry on oeis.org

1, 0, 0, 2, 0, 3, 0, 3, 3, 2, 7, 0, 6, 0, 3, 7, 6, 5, 0, 6, 4, 0, 4, 3, 10, 0, 5, 10, 4, 7, 15, 0, 7, 4, 6, 16, 0, 6, 4, 6, 3, 18, 0, 7, 12, 0, 4, 9, 0, 4, 4, 2, 43, 0, 6, 16, 21, 0, 5, 33, 0, 4, 12, 19, 0, 5, 8, 0, 4, 8, 4, 3, 32, 0, 7, 32, 4, 7, 4, 3, 9, 34, 0, 10, 57
Offset: 1

Views

Author

William Phoenix Marcum, Oct 05 2020

Keywords

Comments

Similar to the Van Eck sequence A181391, except (1) A181391 starts with a 0 instead of a 1, and (2) in A181391 each nonzero term a(n) = m-1 instead of m as in the definition above.

Examples

			a(1) = 1. There is no untouched 1 before a(1), so a(2) = 0. There is no untouched 0 before a(2), so a(3) = 0. a(2) = 0, so a(4) = 2 and a(2) is marked "touched" (we can't use it again, but it is still in the sequence). No untouched 2 yet, so a(5) = 0. a(2) = 0, but it has been touched, while a(3) = 0, so a(6) = 2.
		

Crossrefs

Cf. A181391.

Programs

  • JavaScript
    function a(n) {
      var seq = [1];
      var accseq = [];
      for (var i = 1; i < n; i++) {
        if (accseq.indexOf(seq[seq.length-1]) == -1) {
          seq.push(0);
        } else {
          seq.push(seq.length-accseq.indexOf(seq[seq.length-1]));
          accseq[accseq.indexOf(seq[seq.length-2])] = null;
        }
        accseq.push(seq[seq.length-2]);
      }
      return seq[seq.length-1];
    }

Formula

b(n)=0 => a(n+1)=0; b(n)>0 => a(n+1)=b(n)+1; where b=A181391. - Jan Ritsema van Eck, Jan 09 2021