OFFSET
0,3
COMMENTS
This is a Recamán-like sequence (cf. A005132).
Hans Havermann, running code from Hugo van der Sanden, has found that a(11281) is 3285983871526. - N. J. A. Sloane, Mar 22 2019
If a(n) != -1 then floor((a(n)-1)/2)+n is odd. - Robert Gerbicz, Mar 28 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.
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");
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 *)
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]
(Haskell) a228474 = subtract 1 . length . a248939_row -- Reinhard Zumkeller, Oct 20 2014
(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)
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
CROSSREFS
AUTHOR
Gordon Hamilton, Aug 23 2013
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
STATUS
approved