OFFSET
1,2
COMMENTS
A new number is always followed by a 2.
LINKS
Samuel Harkness, Table of n, a(n) for n = 1..10000
EXAMPLE
a(4) is 3 because the previous term (2) appears two times; we therefore look at the first 2 terms (1,2). 3 is the smallest number not among them, so a(4) is 3.
a(21) is 5: We see that a(20)=4 appears 9 times; the smallest number not among the first 9 terms (1,2,2,3,2,3,3,3,4) is 5.
MATHEMATICA
K = {1}; While[Length@K < 87, T = Take[K, Count[K, Last@K]]; i = 1; While[MemberQ[T, i], i++]; AppendTo[K, i]]; Print[K] (* Samuel Harkness, Mar 12 2023 *)
PROG
(PARI) lista(nn) = my(va=vector(nn)); va[1] = 1; for (n=2, nn, my(k=#select(x->(x==va[n-1]), va)); my(vb=Vec(va, k), m); for(j=1, vecmax(vb)+1, if (! #select(x->(x==j), vb), m=j; break)); va[n] = m; ); va; \\ Michel Marcus, Jan 13 2023
CROSSREFS
KEYWORD
nonn
AUTHOR
Neal Gersh Tolunsky, Jan 11 2023
STATUS
approved