Hello everyone!
The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined as follows: start with any positive integer n. Then each term is obtained from the previous term as follows: if the previous term is even, the next term is one half the previous term. Otherwise, the next term is 3 times the previous term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
I am trying to program something that will show me the amount of steps (of loops) that happened before the number n became smaller than the initial number.
It is the variable dva, but I don't know how to find it!
then I also need to show every step: every value of n (one or each loop) and
Also the highest value that n takes throughout the loops (am)
and the number of steps until n reaches 1 (dv)
I have started something but I feel stuck moving forward as the beginning doesn't even work..
can someone point me to where I'm messing up here?
Sub collatz2()
n = InputBox("type in a number ")
am = 0
Do While n <> 1
If n Mod 2 = 0 Then
n = n * 2
Else: n = n * 3 = 1
End If
If n > am Then
Z = am
End If
x = x + 1
Dim ligne As Integer
'Cells(1, 1).Value = "Trip"
Cells(x, 1).Value = n
Loop
'Cells(1, 2).Value = "Steps"
Cells(x, 2).Value = x
'Cells(1, 3).Value = "Maximal altitude"
Cells(x, 3).Value = am
End Sub
Bookmarks