I decided to do this in the old-fashioned procedural way.
collatz[k_Integer?OddQ] := 3 k + 1
collatz[k_Integer?EvenQ] := k/2
collatzIter[k_ /; k > 2, n_: 125] :=
Module[{i = 0, c0 = k, c1},
While[++i < n,
c1 = collatz[c0];
If[c1 < 2, Break[]];
c0 = c1];
{i, c1}]
Module[{m = 2, r = {0, 0}},
While[r[[2]] <= 4, r = collatzIter[++m]];
{m, r}]
{231, {125, 8}}
Thus 231 is smallest number the where Collatz sequence has an element greater then 4 at position 125, and that element is 8.
Let us check this answer.
<< "ExampleData/Collatz.m"
Collatz[231][[125]]
8
This of course means Collatz[231][[126]]
is 4 and, therefore, fails by KennyColnago's interpretation of the OP's question, because he looks at the 126th element in the Collatz sequence.
Either answer can be easily modified to accommodate the other interpretation of what the OP is asking. The OP will have to tell us which interpretation is correct. In my case, I need only evaluate
Module[{m = 2, r = {0, 0}},
While[r[[2]] <= 4, r = collatzIter[++m, 126]];
{m, r}]
{313, {126, 5}}
to get an answer in agreement with KennyColnago's.
{}
button above the edit window. The edit window help button?
is also useful for learning how to format your questions and answers. You may also find this this meta Q&A helpful $\endgroup$Nest
. I still don't understand what is that function that you need to iterate. Help us to help you, edit to explain better. $\endgroup$m
plays in your question above. You don't appear to use it as part of your recursion. $\endgroup$