cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A340733 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.

This page as a plain text file.
%I A340733 #17 Jun 29 2023 10:39:59
%S A340733 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 A340733 33,60,32,46,76,45,41,48,28,14,27,46,24,63,23,32,74,31,75,61,52,99,84,
%U A340733 133,83,134,128,181,127,89,145,88,30,89,56,40,102,78,142,77,143,210,278,209,139,68
%N A340733 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 A340733 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 A340733 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 A340733 Scott R. Shannon, <a href="/A340733/a340733_1.png">Image of the first 60000 terms</a>.
%F A340733 a(n) = n + 1 for n >= 45256.
%e A340733 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 A340733 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 A340733 (Python)
%o A340733 from itertools import count, islice
%o A340733 def A340733_gen(): # generator of terms
%o A340733     a, ndict = 0, {0:0}
%o A340733     yield 0
%o A340733     for n in count(1):
%o A340733         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 A340733         ndict[a] = n
%o A340733 A340733_list = list(islice(A340733_gen(),30)) # _Chai Wah Wu_, Jun 29 2023
%Y A340733 Cf. A005132, A340593, A340612, A336760, A336761.
%K A340733 nonn
%O A340733 0,3
%A A340733 _Scott R. Shannon_, Jan 17 2021