mirror of
https://github.com/sstent/Advent2021.git
synced 2026-01-27 17:42:17 +00:00
42 lines
752 B
Python
42 lines
752 B
Python
from aocd import get_data
|
|
from aocd import submit
|
|
input_data = get_data(day=2, year=2021)
|
|
|
|
|
|
|
|
test_data = """forward 5
|
|
down 5
|
|
forward 8
|
|
up 3
|
|
down 8
|
|
forward 2"""
|
|
|
|
lines = input_data.split("\n")
|
|
# lines = test_data.split("\n")
|
|
|
|
def split_line(line):
|
|
return line.split(" ")
|
|
|
|
# print(split_line(lines[0]))
|
|
|
|
horizontal = 0
|
|
depth = 0
|
|
aim = 0
|
|
|
|
for line in lines:
|
|
command = split_line(line)
|
|
# print(command)
|
|
if command[0] == "up":
|
|
aim = aim - int(command[1])
|
|
if command[0] == "down":
|
|
aim = aim + int(command[1])
|
|
if command[0] == "forward":
|
|
horizontal = horizontal + int(command[1])
|
|
depth = depth + (aim * int(command[1]) )
|
|
|
|
print(horizontal)
|
|
print(depth)
|
|
print(depth*horizontal)
|
|
|
|
submit(depth*horizontal)
|