%I #37 Mar 24 2023 23:11:57
%S 0,0,-4,0,-47,-46,0,-6362,-23,-22,0,-32,-471,-470,-29,0,-218,-4843985,
%T -39,-38,-657367,0,-101,-57,-56,-7609937,-45,-44,0,-736,-56168428,
%U -3113136,-3113135,-3113134,-3113133,-51,0,-190,-1213998,-1213997,-495,-62,-61,-60
%N Smallest term in wrecker ball sequence starting with n.
%C Starting at n, a(n) is the minimum value reached according to the following rules. On the k-th step (k = 1, 2, 3, ...) move a distance of k in the direction of zero. If the number landed on has been landed on before, move a distance of k away from zero instead. See A228474 and A248939. - _David Nacin_, Mar 15 2019
%C It is currently unproved whether 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, but is certainly greater than 32*10^9. - _M. F. Hasler_, Mar 18 2019
%H M. F. Hasler, <a href="/A248952/b248952.txt">Table of n, a(n) for n = 0..5000</a> (first 1000 terms from Reinhard Zumkeller), Mar 19 2019
%H Gordon Hamilton, <a href="https://www.youtube.com/watch?v=mQdNaofLqVc">Wrecker Ball Sequences</a>, Video, 2013
%F a(n) = smallest term in row n of triangle A248939;
%F a(A000217(n)) = 0; a(A014132(n)) < 0.
%e a(0) = min{0} = 0;
%e a(1) = min{1,0} = 0;
%e a(2) = min{2,1,-1,-4,0} = -4;
%e a(3) = min{3,2,0} = 0;
%e a(4) = min{4,3,1,-2,2,-3,-9,-16,-8,-17,-7,-18,-6,7,21,6,-10,-27,...} = -47;
%e a(5) = min{5,4,2,-1,3,-2,-8,-15,-7,-16,-6,-17,-5,8,22,7,-9,-26,...} = -46;
%e a(6) = min{6,5,3,0} = 0;
%e a(7) = min{7,6,4,1,-3,2,-4,3,-5,-14,-24,-13,-1,12,-2,13,29,46,...} = -6362;
%e a(8) = min{8,7,5,2,-2,3,-3,4,-4,-13,-23,-12,0} = -23;
%e a(9) = min{9,8,6,3,-1,4,-2,5,-3,-12,-22,-11,1,14,0} = -22.
%o (Haskell)
%o import Data.IntSet (singleton, member, insert, findMin, findMax)
%o a248952 n = a248952_list !! n
%o (a248952_list, a248953_list) = unzip $
%o map (\x -> minmax 1 x $ singleton x) [0..] where
%o minmax _ 0 s = (findMin s, findMax s)
%o minmax k x s = minmax (k + 1) y (insert y s) where
%o y = x + (if (x - j) `member` s then j else -j)
%o j = k * signum x
%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 min(d['spots'])
%o # _David Nacin_, Mar 15 2019
%o (Python)
%o def A248952(n):
%o return min(A248939_row(n)); # _M. F. Hasler_, Mar 18 2019
%o (C++) #include<map>
%o long A248952(long n) { long c=0, s, m=0; 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. A228474 (main entry for wrecker ball sequences).
%Y Cf. A248939, A248953, A000217, A014132.
%K sign
%O 0,3
%A _Reinhard Zumkeller_, Oct 18 2014
%E Edited by _M. F. Hasler_, Mar 18 2019