Collatz Steps
The Collatz sequence follows a simple rule: if the number is even, divide it by 2; if it is odd, multiply it by 3 and add 1. Write a function collatz_length that repeats this process until the number becomes 1. Return the number of steps needed to reach 1. For n = 1, there are no steps, so the answer is 0.
Примеры
Ввод
1Вывод
0Ввод
2Вывод
1Ввод
6Вывод
8Нужно реализовать
def collatz_length(n: int) -> int:
Теги
math
Jelentkezz be a beküldési előzmények megtekintéséhez
BejelentkezésJelentkezz be az MI-mentor használatához
BejelentkezésVisible tests
1
Input
1Expected
02
Input
2Expected
13
Input
6Expected
84
Input
7Expected
165
Input
27Expected
1116
Input
16Expected
4Focus radio
Paused · SomaFM · Fluid