I am writing a Sub to identify the longest Collatzs Sequenze between 1 and 1000. How do I need to implement an inner while loop to count the steps of the inner loops to identify the longest Collatz sequence?
Sub LongestCollatz()
Sub LongestCollatz()
VBA Code:
Dim i As Long
Dim maxSteps As Integer
For i = 1 To 1000
If i = 1 Then
maxSteps = CInt(20.856 * Log(2))
Else
maxSteps = CInt(20.856 * Log(i))
End If
If i Mod 2 = 0 Then
i = i / 2
Else
i = 3 * i + 1
End If
Debug.Print i
End If
Next i
End Sub