Add day 2 solution

This commit is contained in:
2021-12-02 18:17:58 +01:00
parent 874453fc1d
commit 3700b24968
2 changed files with 1040 additions and 0 deletions

40
day-02/day-02.py Normal file
View File

@@ -0,0 +1,40 @@
#!/usr/bin/python3
def part_1(input):
h_pos = 0
depth = 0
for line in input:
step = line.split()
if 'forward' == step[0]:
h_pos += int(step[1])
elif 'up' == step[0]:
depth -= int(step[1])
elif 'down' == step[0]:
depth += int(step[1])
result = h_pos * depth
print("Part 1 result:", result)
def part_2(input):
h_pos = 0
depth = 0
aim = 0
for line in input:
step = line.split()
if 'forward' == step[0]:
h_pos += int(step[1])
depth += aim * int(step[1])
elif 'up' == step[0]:
aim -= int(step[1])
elif 'down' == step[0]:
aim += int(step[1])
result = h_pos * depth
print("Part 2 result:", result)
input = list()
with open('input.txt') as fp:
input = fp.readlines()
part_1(input)
part_2(input)

1000
day-02/input.txt Normal file

File diff suppressed because it is too large Load Diff