Create an algorithm that will start with any positive integer n and display the full sequence of numbers that result from the Collatz Conjecture. The COllatz Conjecture is as follows:

  1. start with any positive integer
  2. if the number is even, divide by 2
  3. if the number is odd, multiply by 3 and add 1
  4. repeat steps 2 and 3 until you reach 1

NOTE:

1. My javascript kernel is broken I dont know why.

2. To see outputs highlight the text. My fastpages theme is stuck between darkmode and lightmode so its black text on a black background.

def collatzthis(invalue):
    while invalue != 1:
        print(invalue)
        if invalue % 2 == 0:
            invalue = invalue / 2
        else:
            invalue = invalue * 3
            invalue = invalue + 1
    return(invalue)

values = [6,1,7,23,8,12]
for i in range(len(values)):
    goesin = values[i]
    out = collatzthis(goesin)
    print(int(out))
    print("----------------------------")
6
3.0
10.0
5.0
16.0
8.0
4.0
2.0
1
----------------------------
1
----------------------------
7
22
11.0
34.0
17.0
52.0
26.0
13.0
40.0
20.0
10.0
5.0
16.0
8.0
4.0
2.0
1
----------------------------
23
70
35.0
106.0
53.0
160.0
80.0
40.0
20.0
10.0
5.0
16.0
8.0
4.0
2.0
1
----------------------------
8
4.0
2.0
1
----------------------------
12
6.0
3.0
10.0
5.0
16.0
8.0
4.0
2.0
1
----------------------------
def sqrt(x):
    z = x
    y = x
    while y**2 != x:
        if y**2 > x:
            z = y
            y = y//2
            #print('Low')
        else:
            y = (y+z)//2
            #print('high')
    return y

        
    # theres a surprise in the unformatted markdown for the heading if you look hard enough
    return None
from math import sqrt as sq
test_cases = [0,1,4,85248289,22297284,18939904,91107025,69122596,9721924,37810201,1893294144,8722812816,644398225]
#these were for personal debug please disregard \/
#test_cases = [0,1,4,9,16,25,36,49,64,81,100,121,144]
answers = [int(sq(x)) for x in test_cases]

def checkValid():
    for i in range(len(test_cases)):
        if sqrt(test_cases[i]) == answers[i]:
            print("Check number {} passed".format(i+1))
        else:
            print("Check number {} failed".format(i+1))

checkValid()
Check number 1 passed
Check number 2 passed
Check number 3 passed
Check number 4 passed
Check number 5 passed
Check number 6 passed
Check number 7 passed
Check number 8 passed
Check number 9 passed
Check number 10 passed
Check number 11 passed
Check number 12 passed
Check number 13 passed