The Collatz conjecture (also known as 3n+1 conjecture) is a conjecture that applying the following algorithm to any number we will always eventually reach one:

```
[This is writen in pseudocode]
if(number is even) number = number / 2
if(number is odd) number = 3*number + 1
```

#Task

Your task is to make a function ```hotpo``` that takes a positive ```n``` as input and returns the number of times you need to perform this algorithm to get ```n = 1```.

#Examples

```
hotpo(1) returns 0
(1 is already 1)

hotpo(5) returns 5
5 -> 16 -> 8 -> 4 -> 2 -> 1

hotpo(6) returns 8
6 -> 3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1

hotpo(23) returns 15
23 -> 70 -> 35 -> 106 -> 53 -> 160 -> 80 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1
```

#References
- Collatz conjecture wikipedia page: https://en.wikipedia.org/wiki/Collatz_conjecture

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Mathematics

Starter code: def hotpo(n):
	

Solutions:
def hotpo(n):
	cnt = 0
	while n != 1:
		n = 3 * n + 1 if n % 2 else n / 2
		cnt += 1
	return cnt


def hotpo(num, count=0):
	return count if num == 1 else hotpo(num / 2 if num % 2 == 0 else num * 3 + 1, count + 1)


def hotpo(n):

	def even_odd(m):
		return [3 * m + 1, m / 2][m % 2 == 0]
	c = 0
	while n != 1:
		n = even_odd(n)
		c += 1
	return c


hotpo = lambda n, c=0: c if n == 1 else hotpo(n / 2 if not n % 2 else 3 * n + 1, c + 1)


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


def hotpo(n):
	t = 0
	while n > 1:
		if n % 2 == 0:
			n //= 2
		else:
			n = 3 * n + 1
		t += 1
	return t


def hotpo(n):
	x = 0
	while n > 1:
		if n % 2 == 0:
			n = n / 2
		else:
			n = n * 3 + 1
		x += 1
	return x


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


def hotpo(n, i=0):
	return i if n == 1 else hotpo(int(n / 2) if n % 2 == 0 else 3 * n + 1, i + 1)


def hotpo(n, depth=0):
	return depth if n == 1 else hotpo(3 * n + 1 if n % 2 else n / 2, depth + 1)


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


def hotpo(n: int) -> int:
	seq = []
	while n > 1:
		if not n % 2:
			n = n / 2
		else:
			n = 3 * n + 1
		seq.append(n)
	return len(seq)


hotpo = f = lambda n: n > 1 and -~f([n / 2, 3 * n + 1][n % 2])


def hotpo(n):
	if n == 1:
		return 0
	elif n % 2 == 0:
		return 1 + hotpo(n // 2)
	else:
		return 1 + hotpo(3 * n + 1)


hotpo = lambda n: 1 + hotpo(int(n / 2) if n % 2 == 0 else 3 * n + 1) if n > 1 else 0


def hotpo(n):
	for i in range(999):
		if n == 1:
			return i
		if n % 2:
			n = n * 3 + 1
		else:
			n = n / 2


def hotpo(n):
	if n == 1:
		return 0
	return 1 + hotpo(n / 2) if not n % 2 else 2 + hotpo((n * 3 + 1) / 2)


hotpo = __import__('functools').lru_cache(maxsize=None)(lambda n: 0 if n == 1 else 1 + hotpo(3 * n + 1 if n & 1 else n >> 1))


def hotpo(n, c=0):
	return c if n == 1 else hotpo(3 * n + 1 if n % 2 else n / 2, c + 1)


def hotpo(start, memo={2: 1}):
	n = start
	seq_l = 0
	while n > 1:
		if memo.get(n, False):
			if n != start:
				memo[start] = memo[n] + seq_l
			return memo[n] + seq_l
		if n % 2 == 0:
			n = n // 2
			seq_l += 1
		else:
			n = (n * 3 + 1) // 2
			seq_l += 2
	return 0


def hotpo(n):
	iter = 0
	while n != 1:
		if n % 2 == 0:
			n = n / 2
		elif n % 2 != 0:
			n = 3 * n + 1
		iter = iter + 1
	return iter


def hotpo(n):
	counter = 0
	while n > 1:
		if n % 2:
			n = 3 * n + 1
		else:
			n = n // 2
		counter += 1
	return counter


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


def hotpo(n):
	count = 0
	while n != 1:
		if n % 2 == 0:
			n = n / 2
		elif n % 2 == 1:
			n = 3 * n + 1
		count += 1
	return count


def hotpo(n):
	res = 0
	while n != 1:
		res += 1
		n = n * 3 + 1 if n & 1 else n >> 1
	return res


def hotpo(n):
	temp = [n]
	while True:
		if temp[-1] % 2 != 0:
			if temp[-1] == 1:
				return len(temp) - 1
			temp.append(3 * temp[-1] + 1)
		else:
			temp.append(temp[-1] / 2)


def hotpo(n):
	algorithm_move_counter = 0
	while n > 1:
		if n % 2 == 0:
			n = n / 2
		elif n % 2 > 0:
			n = n * 3 + 1
		algorithm_move_counter += 1
	return algorithm_move_counter


def hotpo(n):
	hops = 0
	while n > 1:
		if n % 2:
			n = 3 * n + 1
		else:
			n /= 2
		hops += 1
	return hops


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


def hotpo(n):
	res = 0
	number = n
	if number == 1:
		return res
	while number != 1:
		if number % 2 == 0:
			number = number / 2
		else:
			number = 3 * number + 1
		res += 1
	return res


from itertools import count

def hotpo(n):
	for i in count():
		if n == 1:
			return i
		if n % 2 == 0:
			n = n / 2
		else:
			n = n * 3 + 1


def hotpo(n, r=0):
	if n == 1:
		return r
	if n % 2:
		return hotpo(3 * n + 1, r + 1)
	return hotpo(n / 2, r + 1)


def hotpo(n):
	nums = []
	while n > 1:
		n = 3 * n + 1 if n & 1 else int(n / 2)
		nums.append(n)
	return len(nums)


def hotpo(n):
	steps = 0
	while n > 1:
		if n % 2 == 0:
			n = n / 2
		else:
			n = n * 3 + 1
		steps = steps + 1
	return steps


def hotpo(n):
	(m, s) = (n, 0)
	while m != 1:
		if m % 2:
			m = 3 * m + 1
		else:
			m //= 2
		s += 1
	return s


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


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


def hotpo(n):
	i = 0
	j = 0
	if n == 1:
		j = 1
	while j != 1:
		if n % 2 == 0:
			n = n / 2
			i += 1
			if n == 1:
				j = 1
		elif n % 2 != 0:
			n = 3 * n + 1
			i += 1
			if n == 1:
				j = 1
	return i


def hotpo(n):
	c = 0
	next_n = n
	while next_n != 1:
		if next_n % 2 == 0:
			next_n = next_n / 2
		else:
			next_n = next_n * 3 + 1
		c += 1
	else:
		return c


def hotpo(n):
	t = 0
	while n != 1:
		if n % 2 == 0:
			n = n / 2
		elif n % 2 == 1:
			n = 3 * n + 1
		t += 1
	return t


def hotpo(n):
	c = 0
	while n != 1:
		(d, r) = divmod(n, 2)
		if r is 0:
			n = d
		else:
			n = 3 * n + 1
		c += 1
	return c


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


def hot(n, i):
	if n == 1:
		return i
	if n % 2:
		return hot(3 * n + 1, i + 1)
	else:
		return hot(n / 2, i + 1)

def hotpo(n):
	i = 0
	return hot(n, i)


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


def hotpo(zahl):
	count = 0
	while zahl > 1:
		count += 1
		if zahl % 2 == 0:
			zahl = zahl / 2
		else:
			zahl = 3 * zahl + 1
	return count


def hotpo(n):
	times = 0
	while True:
		if n == 1:
			break
		n = n // 2 if not n % 2 else n * 3 + 1
		times += 1
	return times


def hotpo(n):
	res = 0
	for i in range(0, 500):
		if n == 1:
			return res
		elif n % 2 == 0:
			n /= 2
			res += 1
		else:
			n = n * 3 + 1
			res += 1


count = 0

def hotpo(n):
	nonlocal count
	if n == 1:
		x = count
		count = 0
		return x
	elif n % 2 == 0:
		count += 1
		return hotpo(n / 2)
	else:
		count += 1
		return hotpo(3 * n + 1)


def hotpo(n):
	if n % 2 == 0 and n > 1:
		n = n // 2
		return 1 + hotpo(n)
	if n % 2 == 1 and n > 1:
		n = 3 * n + 1
		return 1 + hotpo(n)
	return 0


def hotpo(n):
	temp = n
	time = 0
	while temp != 1:
		time += 1
		if temp % 2 == 0:
			temp = temp / 2
		else:
			temp = 3 * temp + 1
	return time


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


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


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


def hotpo(n):
	collatz_counter = 0
	while n > 1:
		if n % 2:
			n = 3 * n + 1
		else:
			n = n / 2
		collatz_counter += 1
	return collatz_counter


def hotpo(n, count=0):
	if n == 1:
		return count
	else:
		n = n / 2 if is_even(n) else 3 * n + 1
		count += 1
		return hotpo(n, count)

def is_even(n):
	return n % 2 == 0


def hotpo(n):
	ct = 0
	while n > 1:
		if n % 2 == 0:
			n = n / 2
		else:
			n = 3 * n + 1
		ct += 1
	return ct