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
Idħol biex tara l-istorja tas-sottomissjonijiet
IdħolIdħol biex tuża l-Mentor tal-AI
IdħolTests12
Visible tests
Test moħbi 7
Test moħbi 8
Test moħbi 9
Test moħbi 10
Test moħbi 11
Test moħbi 12
They run when you press "Submit" — your whole solution is checked against them so you can't hard-code answers for the visible cases.
Focus radio
Paused · SomaFM · Fluid