formations/python-perfs/include/collatz_length_numba.py

12 lines
213 B
Python

from numba import njit
@njit
def collatz_length(n):
if n == 1:
return 0
if n % 2 == 0:
return 1 + collatz_length(n // 2)
elif n % 2 == 1:
return 1 + collatz_length(n * 3 + 1)