-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.py
45 lines (34 loc) · 1.06 KB
/
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
39
40
41
42
43
44
45
INPUT_FILE = f"input/{__file__.split('.')[0].rstrip('b')}"
def getInput():
with open(INPUT_FILE, 'r') as f:
return f.read().splitlines()
def partOne():
inp = getInput()
horizontal = depth = 0
for line in inp:
line = line.strip().split(' ')
if line[0] == "forward":
horizontal += int(line[1])
elif line[0] == "down":
depth += int(line[1])
elif line[0] == "up":
depth -= int(line[1])
return horizontal * depth
def partTwo():
inp = getInput()
horizontal = depth = aim = 0
for line in inp:
line = line.strip().split(' ')
if line[0] == "forward":
horizontal += int(line[1])
depth += (aim * int(line[1]))
elif line[0] == "down":
aim += int(line[1])
elif line[0] == "up":
aim -= int(line[1])
return horizontal * depth
if __name__ == "__main__":
one = partOne()
two = partTwo()
print(f"Part one: {one}")
print(f"Part two: {two}")