aoc-2021/02_day/code.py

23 lines
417 B
Python

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)