aoc/2021/02/02.py

35 lines
732 B
Python
Raw Normal View History

2021-12-06 03:19:11 +00:00
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)