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.
35 lines
627 B
35 lines
627 B
|
|
actions = []
|
|
|
|
with open("input", "r") as file:
|
|
for raw in file.read().splitlines():
|
|
cmd, amount = raw.split(" ")
|
|
actions.append((cmd, int(amount)))
|
|
|
|
x, depth = 0, 0
|
|
for cmd, amount in actions:
|
|
if cmd == "forward":
|
|
x += amount
|
|
if cmd == "up":
|
|
depth -= amount
|
|
if cmd == "down":
|
|
depth += amount
|
|
|
|
print(f"Horizontal: {x}")
|
|
print(f"Depth: {depth}")
|
|
print(x * depth)
|
|
|
|
|
|
x, depth, aim = 0, 0, 0
|
|
for cmd, amount in actions:
|
|
if cmd == "forward":
|
|
x += amount
|
|
depth += aim * amount
|
|
if cmd == "up":
|
|
aim -= amount
|
|
if cmd == "down":
|
|
aim += amount
|
|
|
|
print(f"Horizontal: {x}")
|
|
print(f"Depth: {depth}")
|
|
print(x * depth)
|
|
|