-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay2.py
35 lines (28 loc) · 857 Bytes
/
Day2.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
from PuzzleInput import ReadInput
import numpy as np
pz_input = [x.split(" ") for x in ReadInput(2).data if x != ""]
print(pz_input)
def part_a():
loc = [0, 0]
for command, amount in pz_input:
if command == "forward":
loc[0] += int(amount)
elif command == "down":
loc[1] += int(amount)
elif command == "up":
loc[1] -= int(amount)
return loc[0] * loc[1]
def part_b():
loc = [0, 0, 0]
for command, amount in pz_input:
if command == "forward":
loc[0] += int(amount)
loc[1] += int(amount) * loc[2]
elif command == "down":
loc[2] += int(amount)
elif command == "up":
loc[2] -= int(amount)
return loc[0] * loc[1]
if __name__ == "__main__":
print("Part A", part_a())
print("Part B", part_b())