-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday2.py
42 lines (35 loc) · 850 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
36
37
38
39
40
41
42
### Part 1
lines = []
with open("day2part1.txt", "r") as f:
lines = f.readlines()
x = 0
y = 0
for line in lines:
twoSet = line.split()
if (twoSet[0] == "forward"):
x += int(twoSet[1])
elif (twoSet[0] == "up"):
y -= int(twoSet[1])
elif (twoSet[0] == "down"):
y += int(twoSet[1])
else:
print("error!")
print("X: {} Y: {} X*Y: {}".format(x,y,x*y))
### Part 2
x = 0
y = 0
aim = 0
for line in lines:
twoSet = line.split()
if (twoSet[0] == "forward"):
x += int(twoSet[1])
y += aim*int(twoSet[1])
elif (twoSet[0] == "up"):
# y -= int(twoSet[1])
aim -= int(twoSet[1])
elif (twoSet[0] == "down"):
# y += int(twoSet[1])
aim += int(twoSet[1])
else:
print("error!")
print("X: {} Y: {} aim: {} X*Y: {}".format(x,y,aim,x*y))