-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapCartesianToSpiral.py
63 lines (60 loc) · 1.22 KB
/
MapCartesianToSpiral.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import math
def solution(X, Y):
if X==0 and Y==0:
return 0
x = 0
y = 0
count = 0
if X==Y and X<0:
count = 2*to_it(X)
return count
elif X<0 and abs(X)>=abs(Y):
x = X
y = x
count = 2*to_it(x)
a = -x*2
for i in range(a):
y += 1
count += 1
if x==X and y==Y:
return count
elif abs(Y)<abs(X):
x = -(abs(X)-1)
y = x
count = to_it(x)
elif abs(Y)>=abs(X):
y = -(abs(Y)-1)
x = y
count = to_it(y)
count = count * 2
a = -x*2+1
b = -x*2+2
for i in range(a):
y += 1
count += 1
if x==X and y==Y:
return count
for i in range(a):
x += 1
count += 1
if x==X and y==Y:
return count
for i in range(b):
y -= 1
count += 1
if x==X and y==Y:
return count
for i in range(b):
x -= 1
count += 1
if x==X and y==Y:
return count
return count
pass
def to_it(A):
A = (-A)*2
return int((A+1)*A/2)
pass
if __name__ == "__main__":
q = (int(input()), int(input()))
print(solution(*q))