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.
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, 33, 60, 32, 46, 76, 45, 41, 48, 28, 14, 27, 46, 24, 63, 23, 32, 74, 31, 75, 61, 52, 99, 84, 133, 83, 134, 128, 181, 127, 89, 145, 88, 30, 89, 56, 40, 102, 78, 142, 77, 143, 210, 278, 209, 139, 68
Offset: 0
Keywords
Examples
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.
Links
- Scott R. Shannon, Image of the first 60000 terms.
Programs
-
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 A340733_list = list(islice(A340733_gen(),30)) # Chai Wah Wu, Jun 29 2023
Formula
a(n) = n + 1 for n >= 45256.
Comments