-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday2.py
More file actions
44 lines (34 loc) · 1.24 KB
/
Copy pathday2.py
File metadata and controls
44 lines (34 loc) · 1.24 KB
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
###############################################################################
# Day 2, Task 1 #
###############################################################################
horizontal = 0
vertical = 0
with open("data_day2.txt") as f:
for l in f:
[direction, amount] = l.split(" ")
amount = int(amount)
if direction == "forward":
horizontal += amount
elif direction == "down":
vertical += amount
elif direction == "up":
vertical -= amount
print(horizontal * vertical)
###############################################################################
# Day 2, Task 2 #
###############################################################################
horizontal = 0
vertical = 0
aim = 0
with open("data_day2.txt") as f:
for l in f:
[direction, amount] = l.split(" ")
amount = int(amount)
if direction == "forward":
horizontal += amount
vertical += aim * amount
elif direction == "down":
aim += amount
elif direction == "up":
aim -= amount
print(horizontal * vertical)