login
A349953
a(1)=0 and thereafter a(n) = Min a(i) over those i=1..n-2 with i + a(i+1) = n; or if no such i then a(n) is the least integer >= 2 not in a(1)..a(n-1).
1
0, 2, 0, 3, 4, 0, 5, 3, 6, 5, 0, 7, 8, 3, 9, 8, 10, 0, 11, 7, 12, 13, 3, 14, 13, 8, 15, 16, 0, 17, 18, 7, 13, 12, 19, 20, 3, 18, 20, 21, 8, 22, 15, 23, 7, 0, 24, 17, 25, 26, 23, 27, 12, 28, 3, 29, 22, 18, 30, 20, 31, 32, 8, 24, 33, 15, 34, 35, 36, 0, 37, 38, 17, 39, 22, 40
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
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
Cf. A181391 (Van Eck).
Sequence in context: A181289 A229032 A352835 * A349339 A117909 A261094
KEYWORD
nonn
AUTHOR
Tamas Sandor Nagy, Mar 26 2022
STATUS
approved