%I #24 May 16 2019 01:32:32
%S 0,1,2,3,21,26,6,6843,8,14,10,72,365,366,14,15,352,4674389,18,22,
%T 891114,21,102,23,31,7856204,26,27,28,1700,61960674,3702823,3702824,
%U 3702825,3702826,35,36,370,1047903,1047904,596,41,42,43,2976,45,341,260,261,123
%N Largest term in wrecker ball sequence starting with n.
%C Starting at n, a(n) is the maximum reached according to the following rules: Unless 0 has been reached, on the k-th step (k = 1, 2, 3, ...) move a distance of k in the direction of zero. If the result has already occurred before, move a distance of k away from zero instead. See A228474 and A248939. - _David Nacin_, Mar 15 2019
%C It is currently unproved that all orbits are finite, and therefore unclear whether all a(n) are well defined. In particular, the orbit of n = 11281 is of unknown length > 32*10^9 steps. - _M. F. Hasler_, Mar 18 2019
%H M. F. Hasler, <a href="/A248953/b248953.txt">Table of n, a(n) for n = 0..5000</a> (terms up to n = 1000 from Reinhard Zumkeller), Mar 18 2019
%H Gordon Hamilton, <a href="http://www.youtube.com/watch?v=mQdNaofLqVc">Wrecker Ball Sequences</a>, Video, 2013
%F a(n) = largest term in row n of triangle A248939.
%F a(A000217(n)) = A000217(n).
%e a(0) = max {0} = 0;
%e a(1) = max {1,0} = 1;
%e a(2) = max {2,1,-1,-4,0} = 2;
%e a(3) = max {3,2,0} = 3;
%e a(4) = max {4,3,1,-2,2,-3,-9,-16,-8,-17,-7,-18,-6,7,21,6,-10,-27,...} = 21;
%e a(5) = max {5,4,2,-1,3,-2,-8,-15,-7,-16,-6,-17,-5,8,22,7,-9,-26,...} = 26;
%e a(6) = max {6,5,3,0} = 6;
%e a(7) = max {7,6,4,1,-3,2,-4,3,-5,-14,-24,-13,-1,12,-2,13,29,46,...} = 6843;
%e a(8) = max {8,7,5,2,-2,3,-3,4,-4,-13,-23,-12,0} = 8;
%e a(9) = max {9,8,6,3,-1,4,-2,5,-3,-12,-22,-11,1,14,0} = 14.
%o (Haskell)
%o a248953 n = a248953_list !! n
%o -- See A248952 for definition of a248953_list.
%o (Python)
%o #This and sequences A324660-A324692 generated by manipulating this trip function
%o #spots - positions in order with possible repetition
%o #flee - positions from which we move away from zero with possible repetition
%o #stuck - positions from which we move to a spot already visited with possible repetition
%o def trip(n):
%o stucklist = list()
%o spotsvisited = [n]
%o leavingspots = list()
%o turn = 0
%o forbidden = {n}
%o while n != 0:
%o turn += 1
%o sign = n // abs(n)
%o st = sign * turn
%o if n - st not in forbidden:
%o n = n - st
%o else:
%o leavingspots.append(n)
%o if n + st in forbidden:
%o stucklist.append(n)
%o n = n + st
%o spotsvisited.append(n)
%o forbidden.add(n)
%o return {'stuck':stucklist, 'spots':spotsvisited,
%o 'turns':turn, 'flee':leavingspots}
%o #Actual sequence
%o def a(n):
%o d = trip(n)
%o return max(d['spots'])
%o # _David Nacin_, Mar 15 2019
%o (C++) #include<map>
%o long A248953(long n) { long c=0, s, m=n; for(std::map<long, bool> seen; n; n += seen[n-(s=n>0?c:-c)] ? s:-s) { if(n>m) m=n; seen[n]=true; ++c; } return m; } // _M. F. Hasler_, Mar 18 2019
%Y Cf. A248939 (entire orbit of n), A248952 (minimum of the orbit), A000217, A228474 (length of orbits - 1: main entry for wrecker ball sequences).
%K nonn
%O 0,3
%A _Reinhard Zumkeller_, Oct 18 2014
%E Edited by _M. F. Hasler_, Mar 18 2019