Files
python-aoc-2021/day02/part2.py
2021-12-02 11:43:40 +01:00

19 lines
333 B
Python

#!/usr/bin/env python3
lines = (x.strip() for x in open("input.txt"))
hor = 0
depth = 0
aim = 0
for line in lines:
cmd, strVal = line.split(" ")
val = int(strVal)
if cmd == 'forward':
hor += val
depth += aim * val
elif cmd == 'down':
aim += val
else:
aim -= val
print(hor*depth)