Collatz Investigation

Define the Collatz function:

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

Test it out:

c /@ Range[10]

Iterate the Collatz function for various starting values n:

NestList[c,5,20] (* 20 iterates of c(n) starting with n=5 *)

NestList[c,27,200]

Iterate the Collatz function until we reach 1

Start at n, and return the sequence of iterates until we reach 1:

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

Try it out:

colSeq[27]

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

Max Values

Find the maximum value in the sequence starting at n:

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

colMax[121]

Plot the max for a bunch of values of n:

maxList=colMax/@Range[10000];

ListPlot[maxList] (*,PlotRange->All]*)