-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay2.py
More file actions
31 lines (30 loc) · 856 Bytes
/
Day2.py
File metadata and controls
31 lines (30 loc) · 856 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
def direction():
f = open("input day 2.txt", "r")
lines = f.readlines()
horizontal = 0
depth = 0
for line in lines:
order = line.split(" ")
if order[0] == "forward":
horizontal += int(order[1])
if order[0] == "down":
depth += int(order[1])
if order[0] == "up":
depth -= int(order[1])
print(horizontal * depth)
def direction2():
f = open("input day 2.txt", "r")
lines = f.readlines()
horizontal = 0
depth = 0
aim = 0
for line in lines:
order = line.split(" ")
if order[0] == "forward":
horizontal += int(order[1])
depth += (aim * int(order[1]))
if order[0] == "down":
aim += int(order[1])
if order[0] == "up":
aim -= int(order[1])
print(horizontal * depth)