A228474 Number of steps required to reach zero in the wrecker ball sequence starting with n: On the k-th step (k = 1, 2, 3, ...) move a distance of k in the direction of zero. If the result has occurred before, move a distance of k away from zero instead. Set a(n) = -1 if 0 is never reached.
0, 1, 4, 2, 24, 26, 3, 1725, 12, 14, 4, 26, 123, 125, 15, 5, 119, 781802, 20, 22, 132896, 6, 51, 29, 31, 1220793, 23, 25, 7, 429, 8869123, 532009, 532007, 532009, 532011, 26, 8, 94, 213355, 213353, 248, 33, 31, 33, 1000, 9, 144, 110, 112, 82, 84, 210, 60, 34
Offset: 0
Examples
a(2) = 4 because 2 -> 1 -> -1 -> -4 -> 0. See A248940 for the full 1725-term trajectory of 7. See A248941 for a bigger example, which shows the start of the 701802-term trajectory of 17. - _N. J. A. Sloane_, Mar 07 2019
Links
- Jon E. Schoenfield, Table of n, a(n) for n = 0..10000
- Gordon Hamilton, Wrecker Ball Sequences, Video, 2013. [The sequence is mentioned about 4.5 minutes in to the video. The video begins by discussing A005132. - _N. J. A. Sloane_, Apr 25 2019]
- Hans Havermann, Table of n, a(n) for n = 0..36617
- Hans Havermann, Log-plot of terms through n = 36617
- Hans Havermann, Sharp peaks and high plateaus An overview of large knowns and unknowns up to index 10^6.
- Index entries for sequences related to Recamán's sequence
Crossrefs
Programs
-
Haskell
a228474 = subtract 1 . length . a248939_row -- Reinhard Zumkeller, Oct 20 2014 (C++) #include
-
Julia
function A228474(n) k, position, beenhere = 0, n, [n] while position != 0 k += 1 step = position > 0 ? k : -k position += (position - step) in beenhere ? step : -step push!(beenhere, position) end return length(beenhere) - 1 end println([A228474(n) for n in 0:16]) # Peter Luschny, Mar 24 2019
-
Maple
# To compute at most the first M steps of the trajectory of n: f:=proc(n) local M,i,j,traj,h; M:=200; traj:=[n]; h:=n; s:=1; for i from 1 to M do j:=h-s*i; if member(j,traj,'p') then s:=-s; fi; h:=h-s*i; traj:=[op(traj),h]; if h=0 then return("steps, trajectory =", i, traj); fi; s:=sign(h); od; lprint("trajectory so far = ", traj); error("Need to increase M"); end; # N. J. A. Sloane, Mar 07 2019
-
Mathematica
{0}~Join~Array[-1 + Length@ NestWhile[Append[#1, If[FreeQ[#1, #3], #3, Sign[#1[[-1]] ] (Abs[#1[[-1]] ] + #2)]] & @@ {#1, #2, Sign[#1[[-1]] ] (Abs[#1[[-1]] ] - #2)} & @@ {#, Length@ #} &, {#}, Last@ # != 0 &] &, 16] (* Michael De Vlieger, Mar 27 2019 *)
-
PARI
a(n)={my(M=Map(),k=0); while(n, k++; mapput(M,n,1); my(t=if(n>0, -k, +k)); n+=if(mapisdefined(M,n+t),-t,t)); k} \\ Charles R Greathouse IV, Aug 18 2014, revised Andrew Howroyd, Feb 28 2018 [Warning: requires latest PARI. - N. J. A. Sloane, Mar 09 2019]
Extensions
More terms from Jon E. Schoenfield, Jan 10 2014
Escape clause in definition added by N. J. A. Sloane, Mar 07 2019
Edited by M. F. Hasler, Mar 18 2019
Comments