advent/2021/2/2.py

20 lines
353 B
Python
Raw Normal View History

2022-07-02 16:31:33 -05:00
#!/usr/bin/env python3
inputs = [i.rstrip().split(' ') for i in open("input").readlines()]
aim = 0
depth = 0
horiz = 0
for i in inputs:
inst = i[0]
qty = int(i[1])
if(inst == "forward"):
horiz += qty
depth += aim * qty
if(inst == "down"): aim += qty
if(inst == "up"): aim -= qty
print(depth, horiz, depth*horiz)