mirror of
https://github.com/sstent/Advent2021.git
synced 2026-01-27 09:32:03 +00:00
first
This commit is contained in:
39
Day2_1/main.py
Normal file
39
Day2_1/main.py
Normal file
@@ -0,0 +1,39 @@
|
||||
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)
|
||||
0
Day2_1/promblem.txt
Normal file
0
Day2_1/promblem.txt
Normal file
Reference in New Issue
Block a user