A248961 Sums of wrecker ball sequences starting with n.
0, 1, -2, 5, -292, -241, 14, -437861, -28, -1, 30, 313, -4472, -4223, -2, 55, 3252, -214246256269, -70, -27, 5260887648, 91, -538, -193, -132, -864538549823, -22, 27, 140, 40053, 53088613819206, 86166834699, 86167898716, 86168962733, 86170026754, 49, 204
Offset: 0
Keywords
Examples
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.
Links
- Reinhard Zumkeller, Table of n, a(n) for n = 0..1000
- Gordon Hamilton, Wrecker Ball Sequences, Video, 2013
Programs
-
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
long A248961(long n) { long c=0, d, S=n; for(std::set 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
Comments