login
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

%I #62 Jul 19 2022 08:04:39

%S 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,

%T 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,

%U 29,22,18,30,20,31,32,8,24,33,15,34,35,36,0,37,38,17,39,22,40

%N 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).

%C 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).

%C A given location n might have multiple such candidate a(i), in which case the smallest a(i) is taken.

%C A given location n might have no candidate a(i), and those are filled by successive integers >= 2.

%C 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.

%C 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.

%C 0 occurs infinitely since it is always the smallest candidate.

%C Any number followed by 0 does not reappear, since its candidate location is only its own i + 0 = i.

%C 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.

%H Thomas Scheuerle, <a href="/A349953/b349953.txt">Table of n, a(n) for n = 1..6000</a>

%e a(6) = 0 because a(3) = 0 reappeared 3 places further on in the sequence, as a(4) = 3 has determined this.

%e 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.

%e 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.

%o (MATLAB)

%o function a = A349953( max_n )

%o a(1) = 0;

%o for n = 2:max_n

%o k = findrepeated(a);

%o if ~isempty(k)

%o a = [a min(k)];

%o else

%o z = 2;

%o while ~isempty(find(a == z, 1))

%o z = z+1;

%o end

%o a = [a z];

%o end

%o end

%o end

%o function k = findrepeated( a )

%o k = [];

%o for n = 1:length(a)-1

%o if a(end-n+1) == n+1;

%o k = [k a(end-n)];

%o end

%o end

%o end % _Thomas Scheuerle_, Mar 27 2022

%Y Cf. A181391 (Van Eck).

%K nonn

%O 1,2

%A _Tamas Sandor Nagy_, Mar 26 2022