Collatz Investigation

Define the Collatz function :

c[n_?OddQ]:=3n+1
c[n_?EvenQ]:=n/2

Try it out:

c[5]

c[8]

Iterate this function. Mathematica provides a function called NestList to do this:

NestList[c,5,30]

Produce a sequence of iterates until we find 1

colSeq[n_]:=Module[{ seq={n} }, (* starting sequence *)
While[ Last[seq]≠1,
AppendTo[seq, c[ Last[seq] ] ]
];
seq
]

colSeq[5]

colSeq[27]

ListPlot[colSeq[27],PlotRange->All]

Investigate the length of the Collatz sequences to 1

Function to return the length of the Collatz sequence from n to 1.

colLen[n_]:=Length[colSeq[n]]

ListPlot[ colLen /@ Range[10000] ]

How about the max?

colMax[n_]:=Max[colSeq[n]]

ListPlot[colMax /@Range[10000]]