OFFSET
0,1
COMMENTS
a(0) is the index of the first repeated value in Recamán's sequence (A005132).
a(n) appears to grow like sqrt(2n).
EXAMPLE
For n = 8, the Recamán-like sequence generated is 8, 7, 5, 2, 6, 1; the sequence halts after a(8) = 6 terms since 1 - 6 = -5 is negative and 1 + 6 = 7 is already in the sequence.
PROG
(Python 3)
def seqr(n):
sequence = [n]
i = 1
while True:
if n - i > 0 and n - i not in sequence:
n -= i
sequence.append(n)
elif n + i not in sequence:
n += i
sequence.append(n)
else:
break
i += 1
return len(sequence)
print([seqr(n) for n in range(1000)])
CROSSREFS
KEYWORD
nonn
AUTHOR
Kevin J. Gomez, May 25 2019
STATUS
approved