OFFSET
1,2
COMMENTS
A new number other than 1 is always followed by a 1, so a(n) < n/2 for n > 4.
LINKS
Samuel Harkness, Table of n, a(n) for n = 1..10000
Samuel Harkness, Scatterplot of the first 2000000 terms
EXAMPLE
For a(6), a(5) = 1 has occurred 3 times, so the smallest positive integer not in {a(5), a(4), a(3)} = {1, 3, 1} is 2, thus a(6) = 2.
Next, for a(7), a(6) = 2 has occurred 2 times, so the smallest positive integer not in {a(6), a(5)} = {2, 1} is 3, thus a(7) = 3.
Then, for a(8), a(7) = 3 has occurred 2 times, so the smallest positive integer not in {a(7), a(6)} = {3, 2} is 1, thus a(8) = 1.
Now, for a(9), a(8) = 1 has occurred 4 times, so the smallest positive integer not in {a(8), a(7), a(6), a(5)} = {1, 3, 2, 1} is 4, thus a(9) = 4.
The first terms, alongside the number of times they have occurred o(n), are:
n a(n) o(n)
- ---- ----
1 1 1
2 2 1
3 1 2
4 3 1
5 1 3
6 2 2
7 3 2
8 1 4
9 4 1
10 1 5
MATHEMATICA
V = {1} While[Length[V] < 84, b = 1; While[MemberQ[Take[V, -Count[V, Last[V]]], b], b++ ]; AppendTo[V, b]]; Print[V]
PROG
(PARI) { a = o = vector(84); v = 1; for (n=1, #a, print1 (a[n]=v", "); v=setminus([1..n+1], Set(a[n-o[a[n]]+++1..n]))[1]) } \\ Rémy Sigrist, Jan 09 2023
CROSSREFS
AUTHOR
Samuel Harkness, Dec 06 2022
STATUS
approved