%I #57 Jul 25 2024 14:16:38
%S 1,1,2,1,3,2,2,3,2,4,1,4,2,5,3,3,4,3,5,2,6,2,7,2,8,3,6,2,9,2,10,4,4,5,
%T 3,7,2,11,1,5,4,6,3,8,2,12,4,7,3,9,2,13,2,14,5,5,6,4,8,3,10,2,15,3,11,
%U 2,16,3,12,2,17,4,9,3,13,2,18,3,14,2,19,5,7,4,10,3,15,2,20,2,21,6,5,8,4,11,3,16,2,22
%N a(1) = 1. For n > 1, let m be the number of times that the value a(n-1) has appeared (including its appearance at a(n-1)); if m > 1 then a(n) = m, otherwise a(n) = a(a(n-1)).
%C The sequence refers to itself. If k = a(n-1) is a novel term, then a(n) equals the term whose index is k; otherwise a(n) is the number of times k has appeared in a(1)..a(n-1).
%C All positive integers appear in the sequence.
%C For any n, there exist numbers m > n such that a(m) = a(n), and there exist numbers m > n such that a(m) > a(n).
%C The graph of the largest number a(n) in the interval n = 1..j grows approximately as j^0.66.
%H Thomas Scheuerle, <a href="/A372196/a372196.png">Scatter plot of a(1 to 2000)</a>. Yellow: a(n) = a(a(n-1)), blue: a(n) indicates how often the value of a(n-1) appeared previously.
%e a(1) = 1 by definition.
%e For n = 2, a(1) = 1 has appeared only 1 time, so a(2) = a(a(1)) = a(1) = 1.
%e For n = 3, a(2) = 1 has appeared 2 times, so a(3) = 2.
%e For n = 4, a(3) = 2 has appeared only 1 time, so a(4) = a(a(3)) = a(2) = 1.
%e For n = 5, a(4) = 1 has appeared 3 times, so a(5) = 3.
%e For n = 6, a(5) = 3 has appeared only 1 time, so a(6) = a(a(5)) = a(3) = 2.
%e In the table below, m is the number of times that the value a(n-1) has appeared among the terms a(1)..a(n-1).
%e .
%e n a(n-1) m a(n) comments
%e -- ------ - ---- -----------------------------------
%e 1 - - 1 (by definition)
%e 2 1 1 1 m = 1, so a(2) = a(a(1)) = a(1) = 1
%e 3 1 2 2 m > 1, so a(3) = m
%e 4 2 1 1 m = 1, so a(4) = a(a(3)) = a(2) = 1
%e 5 1 3 3 m > 1, so a(5) = m
%e 6 3 1 2 m = 1, so a(6) = a(a(5)) = a(3) = 2
%e 7 2 2 2 m > 1, so a(7) = m
%e 8 2 3 3 m > 1, so a(8) = m
%e 9 3 2 2 m > 1, so a(9) = m
%e 10 2 4 4 m > 1, so a(10) = m
%o (Python)
%o def generate_sequence(n):
%o sequence = [1]
%o for i in range(1, n):
%o last_number = sequence[-1]
%o if sequence.count(last_number) == 1:
%o next_number = sequence[last_number - 1]
%o else:
%o next_number = sequence.count(last_number)
%o sequence.append(next_number)
%o return sequence
%o n = 30
%o print(generate_sequence(n))
%o (PARI) lista(nn) = my(va= vector(nn)); va[1] = 1; for (n=2, nn, my(nb = #select(x->(x==va[n-1]), va)); if (nb<=1, va[n] = va[va[n-1]], va[n] = nb);); va; \\ _Michel Marcus_, Jul 04 2024
%Y Inspired by A181391.
%K nonn
%O 1,3
%A _Mario Cortés_, Jul 03 2024