-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday2.py
43 lines (37 loc) · 968 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
43
def part1():
x = 0
y = 0
with open('resources/input2.txt') as f:
lines = f.readlines()
for line in lines:
split = line.split(" ")
val = int(split[1])
if split[0] == 'forward':
x = x + val
if split[0] == 'up':
y = y - val
if split[0] == 'down':
y = y + val
print(x, y)
print(x * y)
def part2():
aim = 0
x = 0
y = 0
with open('resources/input2.txt') as f:
lines = f.readlines()
for line in lines:
split = line.split(" ")
val = int(split[1])
if split[0] == 'forward':
x = x + val
y = y + (val * aim)
if split[0] == 'up':
aim = aim - val
if split[0] == 'down':
aim = aim + val
print(aim, x, y)
print(x * y)
if __name__ == '__main__':
part1()
part2()