OFFSET
1,2
COMMENTS
The idea is that a value a(i) may repeat at a distance a(i+1) ahead of i, which is location n = i + a(i+1).
A given location n might have multiple such candidate a(i), in which case the smallest a(i) is taken.
A given location n might have no candidate a(i), and those are filled by successive integers >= 2.
Once a(n) has been determined, it becomes a distance ahead for use with a(n-1). One way to calculate the sequence is to keep track of the smallest candidate at locations ahead, and apply each a(n-1) into them as each a(n) is determined.
A given term repeats in a kind of chain of locations. If that chain is broken because the term was not the smallest candidate, then it never occurs again.
0 occurs infinitely since it is always the smallest candidate.
Any number followed by 0 does not reappear, since its candidate location is only its own i + 0 = i.
This sequence was inspired by Van Eck's sequence (A181391). The question there "Have I seen this before?" changes to here "Will I see this again?", and we count the places forward instead of backward.
LINKS
Thomas Scheuerle, Table of n, a(n) for n = 1..6000
EXAMPLE
a(6) = 0 because a(3) = 0 reappeared 3 places further on in the sequence, as a(4) = 3 has determined this.
a(7) = 5 because no candidate repeating number was determined for this place by any previous term, and 5 is the least integer >= 2 among those not already in the sequence.
For a(14), a(9) = 6 made a(8) = 3, and a(10) = 5 made a(9) = 6 as candidate repeated numbers. Of these, a(8) = 3 is the lesser one, therefore a(14) = 3.
PROG
(MATLAB)
function a = A349953( max_n )
a(1) = 0;
for n = 2:max_n
k = findrepeated(a);
if ~isempty(k)
a = [a min(k)];
else
z = 2;
while ~isempty(find(a == z, 1))
z = z+1;
end
a = [a z];
end
end
end
function k = findrepeated( a )
k = [];
for n = 1:length(a)-1
if a(end-n+1) == n+1;
k = [k a(end-n)];
end
end
end % Thomas Scheuerle, Mar 27 2022
CROSSREFS
KEYWORD
nonn
AUTHOR
Tamas Sandor Nagy, Mar 26 2022
STATUS
approved