advent-of-code/2021/python/day01.py
2022-12-09 11:43:00 -05:00

28 lines
515 B
Python

import shared
def pt1(inp):
count = 0
for x in range(1, len(inp)):
if inp[x] > inp[x - 1]:
count += 1
return count
def pt2(inp):
count = 0
prev = 0
for x in range(2, len(inp)):
window = sum(inp[x - 3 : x])
if window > prev:
count += 1
prev = window
return count
if __name__ == "__main__":
with open(shared.get_fname(1), "r") as f:
inp = [int(x) for x in f.readlines()]
print(pt1(inp))
print(pt2(inp))