Files
advent-of-code/2021/02/part2

27 lines
549 B
Plaintext
Raw Normal View History

2022-01-09 18:36:33 +00:00
#!/usr/bin/env python
depth = 0
hPos = 0
aim = 0
with open('input') as f:
for line in f:
cmd, numStr = line.split(" ", 2)
num = int(numStr)
# match...case is python 3.10+
if cmd == "forward":
hPos = hPos + num
depth = depth + (aim*num)
elif cmd == "backward":
hPos = hPos - num
elif cmd == "up":
aim = aim - num
elif cmd == "down":
aim = aim + num
else:
raise "unknown command: "+cmd
print(depth * hPos)