-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.py
38 lines (30 loc) · 798 Bytes
/
2.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
def solve1(commads) -> int:
depth = 0
position = 0
for c in commands:
if c[0] == "forward":
position += c[1]
if c[0] == "down":
depth += c[1]
if c[0] == "up":
depth -= c[1]
return depth * position
def solve2(commads) -> int:
depth = 0
position = 0
aim = 0
for c in commands:
if c[0] == "forward":
position += c[1]
depth += aim * c[1]
if c[0] == "down":
aim += c[1]
if c[0] == "up":
aim -= c[1]
return depth * position
with open("2.txt", "r") as file:
s = file.read()
commands = [d.split(" ") for d in s.split('\n')]
commands = [(c[0], int(c[1])) for c in commands[:-1]]
print(solve1(commands))
print(solve2(commands))