A340612 a(0) = 0; for n > 0, if n appears in the sequence then a(n) = lastindex(n), where lastindex(n) is the index of the last appearance of n. Otherwise 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, 4, 11, 19, 10, 9, 7, 19, 32, 18, 33, 17, 16, 14, 12, 32, 53, 31, 8, 32, 57, 83, 56, 28, 57, 27, 22, 24, 15, 49, 84, 48, 85, 47, 86, 46, 5, 47, 90, 134, 89, 40, 42, 36, 34, 84, 135, 187, 21, 75, 20, 27, 29, 87, 146, 206, 145, 207, 144, 80, 145, 79, 146, 78, 147, 77, 148, 76, 149
Offset: 0
Keywords
Examples
a(3) = 2, as a(2) = 3 = n, thus a(3) = 2. a(5) = 11, as 5 has not previously appeared in the sequence, but 1 has, a(5) = a(4) + 5 = 6 + 5 = 11. a(11) = 7, as a(7) = 11 = n, thus a(11) = 7.
Links
- Scott R. Shannon, Image of the first 1 million terms.
Programs
-
Python
def aupton(nn): alst, index = [0], {0: 0} # data list, map of last occurrence for n in range(1, nn+1): if n in index: an = index[n] else: an = alst[-1] - n if an < 0 or an in index: an = alst[-1] + n alst.append(an) index[an] = n return alst print(aupton(65)) # Michael S. Branicky, Jan 13 2021
Comments