Add code and description for D2P1 and D2P1
This commit is contained in:
parent
de2ea7c1df
commit
7a10e3afd1
3 changed files with 126 additions and 0 deletions
22
day_02/python/part_1.py
Normal file
22
day_02/python/part_1.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
depth = 0
|
||||
distance = 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
|
||||
elif direction == "up": depth -= magnitude
|
||||
else: depth += magnitude
|
||||
|
||||
print(f"""Distance: {distance}m
|
||||
Depth: {depth}m
|
||||
|
||||
Puzzle Answer: {distance * depth}""")
|
||||
Loading…
Add table
Add a link
Reference in a new issue