login
a(0) = 0, a(n) is the number of x such that a(x) = a(n-1) and there exists no y such that x < y < n and a(y) > a(n-1).
0

%I #23 Nov 29 2018 18:05:07

%S 0,1,1,2,1,1,2,2,3,1,1,2,1,1,2,2,3,2,1,1,2,2,3,3,4,1,1,2,1,1,2,2,3,1,

%T 1,2,1,1,2,2,3,2,1,1,2,2,3,3,4,2,1,1,2,2,3,1,1,2,1,1,2,2,3,2,1,1,2,2,

%U 3,3,4,3,1,1,2,1,1,2,2,3,2,1,1,2,2,3,3,4,4,5

%N a(0) = 0, a(n) is the number of x such that a(x) = a(n-1) and there exists no y such that x < y < n and a(y) > a(n-1).

%C After the n-th occurrence (with n <= m) of m after a number larger than n comes the segment of the sequence from the first appearance of n to the first appearance of m.

%C The first appearance of n in this sequence is given by A002104(n).

%F Let s(n) be the first time n appears in the sequence, then s(n) = Sum_{k=0...n-1} (s(n-1)-s(k)+1).

%e Start with a(0) = 0.

%e No larger number has occurred yet, and the number of 0's since the start of the sequence is 1, so a(1) = 1.

%e No larger number has occurred yet, and the number of 1's since the start of the sequence is 1, so a(2) = 1.

%e Still no larger number has occurred, and the number of 1's since the start of the sequence is 2, so a(3) = 2.

%e No larger number has occurred yet, and the number of 2's since the start of the sequence is 1, so a(4) = 1.

%e The number of 1's that have occurred since the last appearance of a larger number is 1, so a(5) = 1.

%e Etc.

%t a[0] = 0; a[n_] := a[n] = Count[Range[0, n-1], x_ /; a[x] == a[n - 1] && ! AnyTrue[ Range[x+1, n-1], a[#] > a[n-1] &]]; a /@ Range[0, 89] (* _Giovanni Resta_, Oct 22 2018 *)

%o (PARI) lista(nn) = {va = vector(nn); va[1] = 0; for (n=2, nn, nb = 0; forstep (k=n-1, 1, -1, if (va[k] == va[n-1], nb++); if (va[k] > va[n-1], break);); va[n] = nb;); va;} \\ _Michel Marcus_, Oct 22 2018

%Y Cf. A002104.

%K nonn

%O 0,4

%A _Thomas Anton_, Oct 21 2018