You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
337 B
Python
16 lines
337 B
Python
5 years ago
|
def collatz_sequence(x):
|
||
|
num_seq = [x]
|
||
|
if x < 1:
|
||
|
return []
|
||
|
while x > 1:
|
||
|
if x % 2 == 0:
|
||
|
x = x / 2
|
||
|
else:
|
||
|
x = 3 * x + 1
|
||
|
# Added line
|
||
|
num_seq.append(x)
|
||
|
return num_seq
|
||
|
|
||
|
print(collatz_sequence(12))
|
||
|
|
||
|
print(collatz_sequence(19))
|