Ad
Algorithms
Fundamentals

1 of the most famous unsolved math sequences, the aim of this task is this see how many steps it takes for n (positive integer) to end to 1.

The 2 rules of the Conjecture is that if n is even, divide it by 2 and if n is odd, n will equal 3n + 1

for example,
if n = 4,
you would divide n by 2 to get 2
then, u would divide 2 by 2 again to get 1
once you reach one, you check how many steps it took to get to 1. In this case, it would be 2 so return 2.

def collatz(n):
    attempts = 0
    while n != 1:
        if n % 2 == 0:
            n /= 2
            attempts += 1
        else:
            n = (3*n) + 1
            attempts += 1
    return attempts