You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
617 B
26 lines
617 B
import os
|
|
|
|
dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
with open(os.path.join(dir, './input.txt'), 'r') as input_file:
|
|
|
|
lines = input_file.readlines()
|
|
|
|
horizontal = 0
|
|
depth = 0
|
|
aim = 0
|
|
|
|
for line in lines:
|
|
parts = line.split(' ')
|
|
command = parts[0]
|
|
distance = int(parts[1])
|
|
if command == 'forward':
|
|
horizontal = horizontal + distance
|
|
depth = depth + (aim * distance)
|
|
elif command == 'up':
|
|
aim = aim - distance
|
|
elif command == 'down':
|
|
aim = aim + distance
|
|
|
|
|
|
print(horizontal*depth)
|