Compare commits

...

2 Commits

Author SHA1 Message Date
3700b24968 Add day 2 solution 2021-12-02 18:17:58 +01:00
874453fc1d Fix template 2021-12-02 18:17:34 +01:00
3 changed files with 1041 additions and 1 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

View File

@@ -11,7 +11,7 @@ def part_2(input):
result = 0 result = 0
for line in input: for line in input:
pass pass
print("Part 1 result:", result) print("Part 2 result:", result)
input = list() input = list()