login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

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.
2
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,4
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.
LINKS
William Phoenix Marcum, Table of n, a(n) for n = 1..10000
William Marcum, Desmos graph
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
EXAMPLE
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.
PROG
(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];
}
CROSSREFS
Cf. A181391.
Sequence in context: A249901 A253274 A365920 * A373148 A343309 A343488
KEYWORD
nonn,changed
AUTHOR
STATUS
approved