aoc/2021/02/02.py
2021-12-05 21:19:11 -06:00

35 lines
732 B
Python

commands = []
with open("input.txt") as f:
lines = f.readlines()
for line in lines:
commands.append(line)
horizontal = depth = 0
for command in commands:
instruction, amount = command.split(' ')
amount = int(amount)
if instruction == 'forward':
horizontal += amount
elif instruction == 'down':
depth += amount
elif instruction == 'up':
depth -= amount
part1 = horizontal * depth
print(part1)
horizontal = depth = aim = 0
for command in commands:
instruction, amount = command.split(' ')
amount = int(amount)
if instruction == 'down':
aim += amount
elif instruction == 'up':
aim -= amount
elif instruction == 'forward':
horizontal += amount
depth += amount*aim
part2 = horizontal * depth
print(part2)