-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
54 lines (50 loc) · 1.62 KB
/
main.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
def direction(facing, turn):
fast = [360,720,1080,-360,-720,-1080]
facings = ['S', 'SW', 'W','NW', 'N', 'NE', 'E',
'SE',]
if facing not in facings:
raise ValueError('Введіть коректне направлення')
elif turn < -1080 or turn > 1080:
raise ValueError('Введіть число в даіпазоні від -1080 до 1080')
elif turn % 45 != 0:
raise ValueError('Введіть число кратне 45')
if turn < 0:
if turn in fast:
return facing
else:
count = turn // 45
index = facings.index(facing)
if -8 > count > -16:
count = count + 8
elif count < -16:
count = count + 16
else:
count = count
if count + index > -8:
data = count + index
return facings[data]
else:
data = 7 - index
out = count - data
return facings[out-1]
else:
if turn in fast:
return facing
else:
count = turn // 45
index = facings.index(facing)
if 8 < count < 16:
count = count - 8
elif count > 16:
count = count - 16
else:
count = count
if count + index < 8:
data = count + index
return facings[data]
else:
data = 7 - index
out = count - data
return facings[out-1]
v = direction('S', 1035)
print(v)