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.
24 lines
556 B
24 lines
556 B
|
4 years ago
|
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
|
||
|
|
|
||
|
|
for line in lines:
|
||
|
|
parts = line.split(' ')
|
||
|
|
command = parts[0]
|
||
|
|
distance = int(parts[1])
|
||
|
|
if command == 'forward':
|
||
|
|
horizontal = horizontal + distance
|
||
|
|
elif command == 'up':
|
||
|
|
depth = depth - distance
|
||
|
|
elif command == 'down':
|
||
|
|
depth = depth + distance
|
||
|
|
|
||
|
|
print(horizontal*depth)
|