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.
21 lines
464 B
21 lines
464 B
from os import readlink |
|
|
|
|
|
f = open ('input2.txt', 'r') |
|
input = f.readlines() |
|
forward = 0 |
|
depth = 0 |
|
aim = 0 |
|
for i in range(len(input)): |
|
input[i] = input[i].strip() |
|
for i in range(len(input)): |
|
direct, amount = input[i].split(" ", 1) |
|
if direct == 'forward': |
|
forward += int(amount) |
|
depth += aim * int(amount) |
|
if direct == 'down': |
|
aim += int(amount) |
|
if direct == 'up': |
|
aim -= int(amount) |
|
x = depth * forward |
|
print(x)
|
|
|