OFFSET
0,3
COMMENTS
The sequence oscillates erratically from above to below zero. For n <= 10^9 it changes sign 1823 times, with the longest gap between changes occurring from n = 312214179 to n = 703640490, a run of 391426311 negative values. The maximum run without d changing sign starts at n = 726820728 and goes for 43207 values. The longest run of consecutive sign changes in d is four, which occurs four times, at n = 21, 44, 395, and 439. In total d changes sign 675277 times. The largest positive a(n) is for n = 765504445 with a(n) = 496154732190565. The largest negative a(n) is for n = 951481398 with a(n) = -618690200847941.
LINKS
Scott R. Shannon, Table of n, a(n) for n = 1..20000
Scott R. Shannon, Java program to produce the sequence.
EXAMPLE
a(2) = 3, d = 1. For n = 3 as n = |a(2)|, d changes to d = -1. Therefore a(3) = a(2) + d * 3 = 0.
a(8) = -30, d = -1, and a(5) = -9. For n = 9 as n = |a(5)|, d changes to d = 1. Therefore a(9) = a(8) + d * 9 = -21.
MATHEMATICA
s = {0}; d = 1; Do[d *= If[MemberQ[s, n] || MemberQ[s, -n], -1, 1]; AppendTo[s, s[[-1]] + d*n], {n, 1, 60}]; s (* Amiram Eldar, Aug 16 2019 *)
PROG
(PARI) s=0; v=0; d=1; for (n=1, mx=60, print1 (v, ", "); if (bittest(s, n), d=-d); v+=d*n; w=abs(v); if (w<=mx, s=bitor(s, 2^w))) \\ Rémy Sigrist, Aug 16 2019
CROSSREFS
KEYWORD
sign
AUTHOR
Scott R. Shannon, Aug 15 2019
STATUS
approved