-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12.part1.py
60 lines (49 loc) · 1 KB
/
12.part1.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
DEBUG = False
# DEBUG = True
ROTATIONS = {
0: 0,
90: 1,
180: 2,
270: 3,
}
MOVE_DIRECTIONS = {
'F': None,
'N': 0,
'E': 1,
'S': 2,
'W': 3
}
MOVE_VECTORS = {
0: (0, 1),
1: (1, 0),
2: (0, -1),
3: (-1, 0)
}
direction = 1
x = 0
y = 0
with open('12.input') as file:
for line in file:
op = line[0]
arg = int(line[1:-1])
# now with 100% more maps
if op in ['L', 'R']:
rotation = ROTATIONS[arg]
if op == 'R':
direction += rotation
else:
direction -= rotation
direction %= 4
else:
move_direction = MOVE_DIRECTIONS[op]
if move_direction == None:
move_direction = direction
vec = MOVE_VECTORS[move_direction]
x += vec[0] * arg
y += vec[1] * arg
if DEBUG:
print('%d %d' % (x, y))
if DEBUG:
print('')
print('%d %d' % (x, y))
print('%d' % (abs(x) + abs(y)))