This commit is contained in:
2021-12-06 07:37:45 -05:00
commit 6bff0ee551
22 changed files with 5034 additions and 0 deletions

41
Day2_2/main.py Normal file
View File

@@ -0,0 +1,41 @@
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)