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”).

A362373
a(0) = 0; for n > 0, if n appears in the sequence then a(n) is the sum of the indices of all previous appearances of n. Otherwise a(n) = a(n-1) - n if nonnegative and not already in the sequence, otherwise a(n) = a(n-1) + n.
3
0, 1, 3, 2, 6, 11, 4, 11, 19, 10, 9, 12, 11, 24, 38, 23, 7, 24, 42, 8, 28, 49, 27, 15, 30, 5, 31, 22, 20, 49, 24, 26, 58, 25, 59, 94, 130, 93, 14, 53, 13, 54, 18, 61, 17, 62, 16, 63, 111, 50, 49, 100, 48, 39, 41, 96, 40, 97, 32, 34, 94
OFFSET
0,3
COMMENTS
Conjecture: All nonnegative integers appear in this sequence. - Yifan Xie, Apr 24 2023
LINKS
Michael De Vlieger, Log log scatterplot of a(n), n = 1..2^14.
Michael De Vlieger, Log log scatterplot of a(n), n = 1..2^20
EXAMPLE
a(2) = 3 = n, thus a(3) = 2.
a(5) = 11, as 5 has not previously appeared in the sequence, but a(4) - 5 = 1 has, thus a(5) = a(4) + 5 = 6 + 5 = 11.
a(5) and a(7) = 11, and 5 + 7 = 12, thus a(11) = 12.
MATHEMATICA
nn = 120; c[_] := 0; j = a[0] = 0; Do[If[# > 0, Set[k, #], If[And[n <= j, c[#] == 0], Set[k, #], Set[k, j + n]] &[j - n] ] &[c[n]]; c[k] += n; Set[{a[n], j}, {k, k}], {n, nn}], n]; Array[a, nn] (* Michael De Vlieger, Apr 19 2023 *)
PROG
(Python)
from itertools import count, islice
def A362373_gen(): # generator of terms
a, ndict = 0, {0:0}
yield 0
for n in count(1):
yield (a:= ndict[n] if n in ndict else (a-n if a>=n and a-n not in ndict else a+n))
ndict[a] = ndict.get(a, 0)+n
A363373_list = list(islice(A362373_gen(), 30)) # Chai Wah Wu, Jun 29 2023
CROSSREFS
Sequence in context: A369247 A367544 A340612 * A364929 A109876 A108284
KEYWORD
nonn,look,easy
AUTHOR
Kelvin Voskuijl, Apr 17 2023
STATUS
approved