login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A248939 Table read by rows: row n lists the wrecker ball sequence starting with n, or contains -1 if 0 is never reached.. 9
0, 1, 0, 2, 1, -1, -4, 0, 3, 2, 0, 4, 3, 1, -2, 2, -3, -9, -16, -8, -17, -7, -18, -6, 7, 21, 6, -10, -27, -45, -26, -46, -25, -47, -24, 0, 5, 4, 2, -1, 3, -2, -8, -15, -7, -16, -6, -17, -5, 8, 22, 7, -9, -26, -44, -25, -45, -24, -46, -23, 1, 26, 0, 6, 5, 3 (list; graph; refs; listen; history; text; internal format)
OFFSET
0,4
COMMENTS
The wrecker ball sequence starting with n is defined by x[1] = n, and while x[k] is nonzero, x[k+1] = x[k] + s(k)*k, where s(k) = sign(x[k]) if the "candidate" x[k] - sign(x[k])*k had occurred earlier as some x[j], j <= k, and s(k) = -sign(x[k]) else. (This means, from x[k] one moves a distance of k towards the direction of 0 if the result did not occur earlier, or else in the opposite direction.) - M. F. Hasler, Mar 18 2019
A228474(n) + 1 gives the length of row n.
It is currently unproved whether all rows are of finite length. In particular, the length of row 11281 is unknown but larger than 32*10^9. - M. F. Hasler, Mar 18 2019
Hans Havermann, running code from Hugo van der Sanden, has found that row 11281 has length 3285983871527. - N. J. A. Sloane, Mar 22 2019
LINKS
Gordon Hamilton, Wrecker Ball Sequences, Video, 2013
FORMULA
T(n,0) = n;
There are three cases for k > 0:
case T(n,k-1) > 0:
if T(n,k-1) - k != T(n,m), for all m=0..k-1 then T(n,k) = T(n,k-1) - k, otherwise T(n,k) = T(n,k-1) + k,
case T(n,k-1) < 0:
if T(n,k-1) + k != T(n,m), for all m=0..k-1 then T(n,k) = T(n,k-1) + k, otherwise T(n,k) = T(n,k-1) - k,
case T(n,k-1) = 0:
T(n,k) = 0; row ends, i.e., k = A228474(n).
EXAMPLE
0: 0;
1: 1 0;
2: 2 1 -1 -4 0;
3: 3 2 0;
4: 4 3 1 -2 2 -3 -9 -16 -8 -17 -7 -18 -6 7 21 6 -10 -27 -45
-26 -46 -25 -47 -24 0;
5: 5 4 2 -1 3 -2 -8 -15 -7 -16 -6 -17 -5 8 22 7 -9 -26 -44
-25 -45 -24 -46 -23 1 26 0;
6: 6 5 3 0;
7: 7 6 4 1 -3 2 -4 3 -5 -14 -24 -13 -1 12 -2 13 29 . . . . . . . 1730 3445 1729 3446 1728 3447 1727 3448 1726 3449 1725 0;
8: 8 7 5 2 -2 3 -3 4 -4 -13 -23 -12 0;
9: 9 8 6 3 -1 4 -2 5 -3 -12 -22 -11 1 14 0.
MATHEMATICA
row[0] = 0;
row[n_] := Module[{b}, b[0] = n; b[k_] /; b[k-1] > 0 := b[k] = If[AllTrue[ Range[0, k-1], b[k-1] - k != b[#]&], b[k-1] - k, b[k-1] + k]; b[k_] /; b[k-1] < 0 := b[k] = If[AllTrue[Range[0, k-1], b[k-1] + k != b[#]&], b[k-1] + k, b[k-1] - k]; b[k_] /; b[k-1] == 0 := b[k] = 0; Reap[k = 0; While[b[k] != 0, Sow[b[k++]]]; Sow[0]][[2, 1]]];
row /@ Range[0, 16] // Flatten (* Jean-François Alcover, Sep 27 2019 *)
PROG
(Haskell) import Data.IntSet (singleton, member, insert)
a248939 n k = a248939_tabf !! n !! k
a248939_tabf = map a248939_row [0..]
a248939_row n = n : wBall 1 n (singleton n) where
wBall _ 0 _ = []
wBall k x s = y : wBall (k + 1) y (insert y s) where
y = x + (if (x - j) `member` s then j else -j)
j = k * signum x
(PARI) row(n)={my(M=Map(), L=List(), k=0); while(n, k++; listput(L, n); mapput(M, n, 1); my(t=if(n>0, -k, +k)); n+=if(mapisdefined(M, n+t), -t, t)); listput(L, 0); Vec(L)}
for(n=0, 6, print(row(n))) \\ Andrew Howroyd, Mar 01 2018
(Python) def A248939_row(n):
seen = {n}; orbit = [n]; c = 0
while n != 0:
++c; s = c if n>0 else -c; n += s if n-s in seen else -s
seen.add(n); orbit.append(n)
return orbit # M. F. Hasler, Mar 18 2019
(C++) #include <bits/stdc++.h>
A248939_row(long n) { int c=0, s; for(std::map<long, bool> seen; n; n += seen[n-(s=n>0?c:-c)] ? s:-s) { std::cout<<n<<", "; seen[n]=true; ++c; } std::cout<<0; } // M. F. Hasler, Mar 18 2019
CROSSREFS
Cf. A228474 (row lengths - 1), A248961 (row sums), A248973 (partial sums per row), A248952 (min per row), A248953 (max per row), A001532 (Recamán).
Cf. A248940 (row 7), A248941 (row 17), A248942 (row 20).
Sequence in context: A010247 A087605 A251636 * A106246 A340660 A136674
KEYWORD
sign,tabf
AUTHOR
Reinhard Zumkeller, Oct 17 2014
EXTENSIONS
Escape clause added by N. J. A. Sloane, Apr 19 2019
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified February 28 20:40 EST 2024. Contains 370400 sequences. (Running on oeis4.)