OFFSET
1,4
COMMENTS
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
KEYWORD
nonn
AUTHOR
William Phoenix Marcum, Oct 05 2020
STATUS
approved