aoc/2021/01/01.py

20 lines
526 B
Python
Raw Normal View History

2021-12-06 03:19:11 +00:00
sweep = []
with open("input.txt") as f:
lines = f.readlines()
for line in lines:
sweep.append(int(line))
comparison = zip(sweep[1:],sweep)
differences = [(d2 - d1) for d2, d1 in comparison]
increases = [(d > 0) for d in differences]
part1 = sum(increases)
print(part1)
window = zip(sweep,sweep[1:],sweep[2:])
sums = [(d1 + d2 + d3) for d1, d2, d3 in window]
comparison = zip(sums[1:],sums)
differences = [(d2 - d1) for d2, d1 in comparison]
increases = [(d > 0) for d in differences]
part2 = sum(increases)
print(part2)