cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

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.

Original entry on oeis.org

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

Views

Author

Gordon Hamilton, Aug 23 2013

Keywords

Comments

This is a Recamán-like sequence (cf. A005132).
The n-th triangular number A000217(n) has a(A000217(n)) = n.
a(n) + 1 = length of row n in tables A248939 and A248973. - Reinhard Zumkeller, Oct 20 2014
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

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
		

Crossrefs

Cf. A248939 (rows = the full sequences), A248961 (row sums), A248973 (partial sums per row), A248952 (min per row), A248953 (max per row).
Cf. also A248940 (row 7), A248941 (row 17), A248942 (row 20).
Cf. also A000217, A005132 (Recamán).

Programs

  • Haskell
    a228474 = subtract 1 . length . a248939_row  -- Reinhard Zumkeller, Oct 20 2014
    (C++) #include 
      int A228474(long n) { int c=0, s; for(std::map 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
  • 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