-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay2.py
47 lines (37 loc) · 1.31 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
def part_1() -> None:
h_pos: int = 0
v_pos: int = 0
with open("../data/day2.txt", "r") as dFile:
for row in dFile.readlines():
value: int = int(row.split(" ")[1])
match row.split(" ")[0]:
case "forward":
h_pos += value
case "down":
v_pos += value
case "up":
v_pos -= value
case _:
raise ValueError(f"Unsupported command {row.split(' ')[0]}")
print("Day: 2 | Part: 1 | Result:", h_pos * v_pos)
def part_2() -> None:
h_pos: int = 0
v_pos: int = 0
aim : int = 0
with open("../data/day2.txt", "r") as dFile:
for row in dFile.readlines():
value: int = int(row.split(" ")[1])
match row.split(" ")[0]:
case "forward":
h_pos += value
v_pos += value * aim
case "down":
aim += value
case "up":
aim -= value
case _:
raise ValueError(f"Unsupported command {row.split(' ')[0]}")
print("Day: 2 | Part: 2 | Result:", h_pos * v_pos)
if __name__ == "__main__":
part_1()
part_2()