Language/Python

[Python / 프로그래머스 level 1] 콜라츠 추측

ej503 2021. 6. 18. 14:29

def solution(n):
    cnt = 0
    while n > 1:
        if n % 2 == 0:
            n = n // 2
        else:
            n = (n * 3) + 1
        cnt+=1
        if cnt >= 500:
            return -1
    return cnt