I have 3 lines of code that does the Collatz Conjecture in mathematica. the code is the following:
ClearAll[collatz];
collatz[1] = 1;
collatz[n_ /; EvenQ[n]] := (Sow[n]; collatz[n/2])
collatz[n_ /; OddQ[n]] := (Sow[n]; collatz[3 n + 1])
runcoll[n_] := Reap[collatz[n]]
this code performs until 1 is reached but I want to have the code done a specificities cnumber of times, say 10. how can I write a loop that perform this only a specific number of times?
and this has not happed btw:
ClearAll[collatz];
collatz[1] = 1;
n=1; While [n<11,
collatz[n_ /; EvenQ[n]] := (Sow[n]; collatz[n/2])
collatz[n_ /; OddQ[n]] := (Sow[n]; collatz[3 n + 1])
runcoll[n_] := Reap[collatz[n]]
; n++]