|
|
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.
|
|
42
|
|
|
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
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
0,3
|
|
COMMENTS
|
This is a Recamán-like sequence (cf. A005132).
If a(n) != -1 then floor((a(n)-1)/2)+n is odd. - Robert Gerbicz, Mar 28 2019
|
|
LINKS
|
|
|
EXAMPLE
|
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
|
|
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");
|
|
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 *)
|
|
PROG
|
(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]
(C++) #include <map>
int A228474(long n) { int c=0, s; for(std::map<long, bool> seen; n; n += seen[n-(s=n>0?c:-c)] ? s:-s) { seen[n]=true; ++c; } return c; } // M. F. Hasler, Mar 18 2019
(Julia)
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
|
|
CROSSREFS
|
|
|
KEYWORD
|
|
|
AUTHOR
|
|
|
EXTENSIONS
|
|
|
STATUS
|
approved
|
|
|
|