OFFSET
1,3
COMMENTS
REFERENCES
M. J. Halm, Sequences (Re)discovered, Mpossibilities 81 (Aug. 2002), p. 1.
LINKS
FORMULA
a(1) = 0; and for n > 1, if n is odd, a(n) = 1 + a(3n+1), and if n is even, a(n) = 1 + min(a(3n+1),a(n/2)). [But with a similar caveat as in A257265] - Antti Karttunen, Aug 20 2017
EXAMPLE
Several early values use the path:
6 -> 3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1.
The first path where choosing 3x+1 for even x helps is:
9 -> 28 -> 85 -> 256 -> 128 -> 64 -> 32 -> 16 -> 8 -> 4 -> 2 -> 1.
MAPLE
# Code from David Applegate: Be careful - the function takes an iteration limit and returns the limit if it wasn't able to determine the answer (that is, if A127885(n, lim) == lim, all you know is that the value is >= lim). To use it, do manual iteration on the limit.
A127885 := proc(n, lim) local d, d2; options remember;
if (n = 1) then return 0; end if;
if (lim <= 0) then return 0; end if;
if (n > 2 ^ lim) then return lim; end if;
if (n mod 2 = 0) then
d := A127885(n/2, lim-1);
d2 := A127885(3*n+1, d);
if (d2 < d) then d := d2; end if;
else
d := A127885(3*n+1, lim-1);
end if;
return 1+d;
end proc;
MATHEMATICA
Table[-1 + Length@ NestWhileList[Flatten[# /. {k_ /; OddQ@ k :> 3 k + 1, k_ /; EvenQ@ k :> {k/2, 3 k + 1}}] &, {n}, FreeQ[#, 1] &], {n, 126}] (* Michael De Vlieger, Aug 20 2017 *)
PROG
(PARI) { A127885(n) = my(S, k); S=[n]; k=0; while( S[1]!=1, k++; S=vecsort( concat(apply(x->3*x+1, S), apply(x->x\2, select(x->x%2==0, S) )), , 8); ); k } /* Max Alekseyev, Sep 03 2015 */
KEYWORD
nonn
AUTHOR
David Applegate and N. J. A. Sloane, Feb 04 2007
EXTENSIONS
Escape clause added to definition by N. J. A. Sloane, Aug 20 2017
STATUS
approved