Files
Advent2021/Day2_1/main.py
2021-12-06 07:37:45 -05:00

40 lines
703 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
for line in lines:
command = split_line(line)
# print(command)
if command[0] == "up":
depth = depth - int(command[1])
if command[0] == "down":
depth = depth + int(command[1])
if command[0] == "forward":
horizontal = horizontal + int(command[1])
print(horizontal)
print(depth)
print(depth*horizontal)
submit(depth*horizontal)