aoc-2021/02_day/code.py

24 lines
417 B
Python
Raw Normal View History

2021-12-05 15:52:20 +00:00
import fileinput
data = []
for inp in fileinput.input():
val = inp.strip()
if val != '':
cmd, v = val.split()
data.append((cmd, int(v)))
horizontal = 0
aim = 0
depth = 0
for cmd, val in data:
if cmd == 'forward':
horizontal+=val
depth+=aim*val
if cmd == 'down':
aim+=val
if cmd == 'up':
aim-=val
print(horizontal, depth)
print(horizontal* depth)