blob: 1fcb2a86ed06d96dd87daa6ccae69863939f8c5b (
plain)
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
|
import sys
data = sys.argv[1] if len(sys.argv) > 1 else "../day2data.txt"
fwd1 = 0
depth1 = 0
fwd2 = 0
depth2 = 0
aim = 0
for line in open(data):
cmd, amt = line.split()
amt = int(amt)
if cmd == "forward":
fwd1 += amt
fwd2 += amt
depth2 += amt * aim
elif cmd == "up":
depth1 -= amt
aim -= amt
else:
assert cmd == "down"
depth1 += amt
aim += amt
print(fwd1 * depth1)
print(fwd2 * depth2)
|