ASCIIsite/tests/control/dir/collatz.py

17 lines
364 B
Python
Raw Permalink Normal View History

def nextInSequence(number):
if isinstance(number, int):
if number % 2 == 0:
return number // 2
else:
return 3*number+1
else:
raise TypeError('input must be int!')
def seqenceLength(number):
length = 0
while number != 1:
number = nextInSequence(number)
length += 1
return length