aoc2021/day01.py
Stefan Harmuth d07daa6422 day01
2021-12-01 06:13:44 +01:00

32 lines
663 B
Python

from aoc import AOCDay
class Day(AOCDay):
test_solutions_p1 = [7]
test_solutions_p2 = [5]
def part1(self):
count = 0
depths = self.getInputListAsType(int)
for i, x in enumerate(depths):
if i == 0:
continue
if x > depths[i-1]:
count += 1
return count
def part2(self):
count = 0
depths = self.getInputListAsType(int)
for x in range(3, len(depths)):
mid = depths[x-2] + depths[x-1]
a = mid + depths[x-3]
b = mid + depths[x]
if a < b:
count += 1
return count