0
0
Fork 0
AdventOfCode/day_02/python/part_2.py
2021-12-29 19:34:52 -07:00

28 lines
No EOL
580 B
Python

depth = 0
distance = 0
aim = 0
with open("../input", "r") as file:
instructions = file.read().split("\n")
# Follow each instruction
for instruction in instructions:
# Parse the instruction into usable data
direction, magnitude = instruction.split(" ")
magnitude = int(magnitude)
# Modify the submarine coordinates as needed
if direction == "forward":
distance += magnitude
depth += aim * magnitude
elif direction == "up":
aim -= magnitude
else:
aim += magnitude
print(f"""Distance: {distance}m
Depth: {depth}m
Aim: {aim}
Puzzle Answer: {distance * depth}""")