OFFSET
0,3
COMMENTS
This sequence uses the same rules as Recamán's sequence A005132 if the value of n itself has not previously appeared in the sequence. However if n has previously appeared then the step size from a(n-1) is set to be n - index(n), where index(n) is the sequence index of the last appearance of n.
The sequence values appear random up to a(45256) = 45257. As 45257 has then appeared in the sequence the step size for the next term is 45257 - index(45257) = 45257 - 452576 = 1. As a(42564) = 45256 the next term a(45257) must be a(45256) + 1 = 45257 + 1 = 45258. This pattern then repeats so all terms beyond a(45256) are just a(n-1) + 1. See the linked image.
LINKS
Scott R. Shannon, Image of the first 60000 terms.
FORMULA
a(n) = n + 1 for n >= 45256.
EXAMPLE
a(3) = 2 as a(2) = 3 = n, thus the step size from a(2) is 3 - index(3) = 3 - 2 = 1. As 2 has not previously appeared a(3) = a(2) - 1 = 3 - 1 = 2.
a(6) = 9 as a(4) = 6 = n, thus the step size from a(5) is 6 - index(6) = 6 - 4 = 2. As 9 has not previously appeared a(6) = a(5) - 2 = 11 - 2 = 9.
PROG
(Python)
from itertools import count, islice
def A340733_gen(): # generator of terms
a, ndict = 0, {0:0}
yield 0
for n in count(1):
yield (a:= (a-m if a>=(m:=n-ndict[n]) and a-m not in ndict else a+m) if n in ndict else (a-n if a>=n and a-n not in ndict else a+n))
ndict[a] = n
CROSSREFS
KEYWORD
nonn
AUTHOR
Scott R. Shannon, Jan 17 2021
STATUS
approved