OFFSET
0,3
COMMENTS
This sequences 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 lastindex(n), where lastindex(n) is the sequence index of the last appearance of n.
The smallest value not to have appeared after 1 million terms is 52. It is unknown if all terms eventually appear.
EXAMPLE
a(3) = 5 as a(2) = 3 = n, thus the step size from a(2) is 2. As 1 has previously appeared a(3) = a(2) + 2 = 3 + 2 = 5.
a(5) = 6 as a(3) = 5 = n, thus the step size from a(4) is 3. As 6 has not previously appeared a(5) = a(4) - 3 = 9 - 3 = 6.
PROG
(Python)
from itertools import count, islice
def A340593_gen(): # generator of terms
a, ndict = 0, {0:0}
yield 0
for n in count(1):
yield (a:= (a-m if a>=(m:=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 13 2021
STATUS
approved