34 lines
594 B
Python
34 lines
594 B
Python
import math
|
|
|
|
n = 142
|
|
|
|
direction = 0
|
|
x = 0
|
|
y = 0
|
|
avancer = 1
|
|
|
|
while n != 1:
|
|
print(n)
|
|
if n%2 == 1:
|
|
if n%3 == 0:
|
|
direction = direction + 1
|
|
else:
|
|
direction = direction - 1
|
|
else:
|
|
if direction%4 == 0:
|
|
y = y + avancer
|
|
elif direction%4 == 1:
|
|
x = x + avancer
|
|
elif direction%4 == 2:
|
|
y = y - avancer
|
|
else:
|
|
x = x - avancer
|
|
avancer = avancer + 1
|
|
|
|
|
|
if n%2 == 0:
|
|
n = n//2
|
|
else:
|
|
n = n * 3 + 1
|
|
|
|
print("Distance: ", 1000*math.sqrt(x*x+y*y)) |