-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday2.py
More file actions
34 lines (27 loc) · 731 Bytes
/
Copy pathday2.py
File metadata and controls
34 lines (27 loc) · 731 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
from util import read_from_file
F = "forward"
D = "down"
U = "up"
class Direction:
def __init__(self, rawtext):
d, n = rawtext.split(" ")
self.direction = d
self.magnitude = int(n)
def run():
directions = [Direction(l) for l in read_from_file("data/day2.txt")]
hor = 0
dep = 0
aim = 0
for d in directions:
if d.direction == F:
hor += d.magnitude
dep += aim * d.magnitude
elif d.direction == D:
aim += d.magnitude
elif d.direction == U:
aim -= d.magnitude
else:
raise Exception("WTF IS THIS SHIT MAN: %s", d.direction)
print(hor * dep)
if __name__ == "__main__":
run()