-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.py
More file actions
38 lines (31 loc) · 852 Bytes
/
Copy path2.py
File metadata and controls
38 lines (31 loc) · 852 Bytes
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
# part 1
horizontal_position = 0
depth = 0
with open('2.txt') as f:
for line in f.readlines():
direction, num = line.split(' ')
num = int(num)
if direction == 'forward':
horizontal_position += num
elif direction == 'down':
depth += num
elif direction == 'up':
depth -= num
print(horizontal_position * depth)
horizontal_position = 0
depth = 0
aim = 0
# part 2
with open('2.txt') as f:
for line in f.readlines():
direction, num = line.split(' ')
num = int(num)
if direction == 'forward':
horizontal_position += num
depth += aim * num
elif direction == 'down':
aim += num
elif direction == 'up':
aim -= num
print(horizontal_position, depth)
print(horizontal_position * depth)