login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

a(0) = 0; for n > 0, if the value of n itself appears in the sequence then a(n) = a(n-1) - (n-index(n)) if nonnegative and not already in the sequence, otherwise a(n) = a(n-1) + (n-index(n)), where index(n) is the index of the last appearance of n. If the value of n does not appear then a(n) = a(n-1) - n if nonnegative and not already in the sequence, otherwise a(n) = a(n-1) + n.
1

%I #17 Jun 29 2023 10:39:59

%S 0,1,3,2,6,11,9,16,8,5,15,21,33,20,34,29,38,55,37,18,25,35,13,36,12,7,

%T 33,60,32,46,76,45,41,48,28,14,27,46,24,63,23,32,74,31,75,61,52,99,84,

%U 133,83,134,128,181,127,89,145,88,30,89,56,40,102,78,142,77,143,210,278,209,139,68

%N a(0) = 0; for n > 0, if the value of n itself appears in the sequence then a(n) = a(n-1) - (n-index(n)) if nonnegative and not already in the sequence, otherwise a(n) = a(n-1) + (n-index(n)), where index(n) is the index of the last appearance of n. If the value of n does not appear then a(n) = a(n-1) - n if nonnegative and not already in the sequence, otherwise a(n) = a(n-1) + n.

%C 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.

%C 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.

%H Scott R. Shannon, <a href="/A340733/a340733_1.png">Image of the first 60000 terms</a>.

%F a(n) = n + 1 for n >= 45256.

%e 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.

%e 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.

%o (Python)

%o from itertools import count, islice

%o def A340733_gen(): # generator of terms

%o a, ndict = 0, {0:0}

%o yield 0

%o for n in count(1):

%o 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))

%o ndict[a] = n

%o A340733_list = list(islice(A340733_gen(),30)) # _Chai Wah Wu_, Jun 29 2023

%Y Cf. A005132, A340593, A340612, A336760, A336761.

%K nonn

%O 0,3

%A _Scott R. Shannon_, Jan 17 2021