aoc2021/2/b.py

25 lines
366 B
Python

with open("input.txt") as f:
lines = [i for i in f.readlines()]
depth = 0
hpos = 0
aim = 0
for line in lines:
verb, val = line.strip().split()
val = int(val)
if verb == "forward":
hpos += val
depth += (aim * val)
elif verb == "down":
aim += val
elif verb == "up":
aim -= val
print(depth * hpos)
# 5m16s