OFFSET
1,3
COMMENTS
The Collatz function (related to the "3x+1 problem") is defined by: f(n) = n/2 if n is even; f(n) = 3n + 1 if n is odd. A famous conjecture states that n, f(n), f(f(n)), .... eventually reaches 1.
a(n) = A006667(n) + 1; a(A000079(n))=1; a(A062052(n))=2; a(A062053(n))=3; a(A062054(n))=4; a(A062055(n))=5; a(A062056(n))=6; a(A062057(n))=7; a(A062058(n))=8; a(A062059(n))=9; a(A062060(n))=10. - Reinhard Zumkeller, Oct 08 2011
The count includes also the starting value n if it is odd. See A286380 for the version which never includes n itself. - Antti Karttunen, Aug 10 2017
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 1..10000
Chris K. Caldwell and G. L. Honaker, Jr., Prime curio for 41 (which says 41 is a fixed point)
Eric Weisstein's World of Mathematics, Collatz Problem
Wikipedia, Collatz conjecture
FORMULA
EXAMPLE
The terms n, f(n), f(f(n)), ...., 1 for n = 12 are: 12, 6, 3, 10, 5, 16, 8, 4, 2, 1, of which 3 are odd. Hence a(12) = 3.
MATHEMATICA
f[n_] := Module[{a, i, o}, i = n; o = 1; a = {}; While[i > 1, If[Mod[i, 2] == 1, o = o + 1]; a = Append[a, i]; i = f[i]]; o]; Table[f[i], {i, 1, 100}]
Table[Count[NestWhileList[If[EvenQ[#], #/2, 3 # + 1] &, n, # > 1 &], _?OddQ], {n, 94}] (* Jayanta Basu, Jun 15 2013 *)
PROG
(Haskell)
a078719 =
(+ 1) . length . filter odd . takeWhile (> 2) . (iterate a006370)
a078719_list = map a078719 [1..]
-- Reinhard Zumkeller, Oct 08 2011
(PARI) a(n) = {my(x=n, v=List([])); while(x>1, if(x%2==0, x=x/2, listput(v, x); x=3*x+1)); 1+#v; } \\ Jinyuan Wang, Dec 29 2019
CROSSREFS
KEYWORD
nonn
AUTHOR
Joseph L. Pe, Dec 20 2002
EXTENSIONS
"Escape clause" added to definition by N. J. A. Sloane, Jun 06 2017
STATUS
approved