OFFSET
0,3
COMMENTS
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 0..1000
Gordon Hamilton, Wrecker Ball Sequences, Video, 2013
EXAMPLE
a(1) = 1+0 = 1;
a(2) = 2+1-1-4+0 = -2;
a(3) = 3+2+0 = 5;
a(4) = 4+3+1-2+2-3-9-16-8-17-7-18-6+7+21+6-10-27-45-26-46-25-47-24+0 = -292;
a(5) = 5+4+2-1+3-2-8-15-7-16-6-17-5+8+22+7-9-26-44-25-45-24-46-... = -241;
a(6) = 6+5+3+0 = 14;
a(7) = 7+6+4+1-3+2-4+3-5-14-24-13-1+12-2+13+29+46+28+9-11+10-... = -437861;
a(8) = 8+7+5+2-2+3-3+4-4-13-23-12+0 = -28;
a(9) = 9+8+6+3-1+4-2+5-3-12-22-11+1+14+0 = -1.
PROG
(Haskell) import Data.IntSet (singleton, member, insert)
a248961 n = addup 1 n 0 $ singleton n where
addup _ 0 sum _ = sum
addup k x sum s = addup (k + 1) y (sum + x) (insert y s) where
y = x + (if (x - j) `member` s then j else -j)
j = k * signum x
(C++) #include<set>
long A248961(long n) { long c=0, d, S=n; for(std::set<long> A; n; A.insert(n), S += n += A.count(n - (d = n>0 ? c : -c)) ? d : -d) ++c; return S; } // M. F. Hasler, Mar 19 2019
(PARI) A248961(n, A=[n], c, S=n)={while( n+=sign(n)*if(setsearch(A, n-sign(n)*c+=1), c, -c), A=setunion(A, [n]); S+=n); S} \\ M. F. Hasler, Mar 19 2019
(Python) def A248961(n):
A = {n}; c = 0; S = 0
while n != 0:
++c; s = c if n>0 else -c; n += s if n-s in A else -s; A.add(n); S += n
return S # M. F. Hasler, Mar 19 2019
CROSSREFS
KEYWORD
sign
AUTHOR
Reinhard Zumkeller, Oct 18 2014
STATUS
approved