A328342 a(0) = 0; for n > 1, if a(n-1) has appeared three or more times then a(n) = total number of terms between the last and second-last appearance of a(n-1), minus the total number of terms between the second-last and third-last appearance of a(n-1). If a(n-1) has appeared two times, a(n) = total number of terms between the last and second-last appearance of a(n-1). If a(n-1) has appeared once, a(n) = 0.
0, 0, 1, 0, 1, 2, 0, 1, 1, -2, 0, 1, 2, 7, 0, 0, -3, 0, 1, 4, 0, 1, -4, 0, 0, -2, 16, 0, 2, 9, 0, 0, -2, -9, 0, 2, -9, 3, 0, 1, 15, 0, -1, 0, -1, 2, 3, 9, 18, 0, 4, 31, 0, -3, 37, 0, 0, -2, 18, 10, 0, 3, 6, 0, -1, 18, -3, -24, 0, 2, 14, 0, -2, -10, 0, 0, -2, -11, 0, 2, -14
Offset: 0
Keywords
Examples
a(1) = 0 as a(1-1) = a(0) = 0 has only appeared once. a(2) = 1 as a(2-1) = a(1) = 0 has appeared twice, and the number of terms between the last and second-last appearance of 0, a(0) and a(1), is 1 a(4) = 1. a(4-1) = a(3) = 0, which has appeared three times. The number of terms between the last and second-last appearance of 0, a(3) and a(1), is 2. The number of terms between the second-last and third-last appearance of 0, a(1) and a(0), is 1. Thus a(4) = 2 - 1 = 1. a(9) = -2. a(9-1) = a(8) = 1, which has appeared three times. The number of terms between the last and second-last appearance of 1, a(8) and a(7), is 1. The number of terms between the second-last and third-last appearance of 1, a(7) and a(4), is 3. Thus a(9) = 1 - 3 = -2.
Links
- Scott R. Shannon, Java code to produce the sequence.
Programs
-
Mathematica
s = {0}; Do[d = Differences[Position[s, ?(# == s[[-1]] &)] // Flatten]; a = Switch[Length[d], 0, 0, 1, d[[1]], , d[[-1]] - d[[-2]]]; AppendTo[s, a], {80}]; s (* Amiram Eldar, Oct 13 2019 *)
Comments