25 lines
511 B
Python
Executable File
25 lines
511 B
Python
Executable File
#!/usr/bin/env python
|
|
|
|
depth = 0
|
|
hPos = 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
|
|
elif cmd == "backward":
|
|
hPos = hPos - num
|
|
elif cmd == "up":
|
|
depth = depth - num
|
|
elif cmd == "down":
|
|
depth = depth + num
|
|
else:
|
|
raise "unknown command: "+cmd
|
|
|
|
print(depth * hPos)
|
|
|