OFFSET
0,3
COMMENTS
Conjecture: All nonnegative integers appear in this sequence. - Yifan Xie, Apr 24 2023
LINKS
Michael De Vlieger, Table of n, a(n) for n = 0..16384
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
CROSSREFS
KEYWORD
AUTHOR
Kelvin Voskuijl, Apr 17 2023
STATUS
approved