aoc2021/d01/d01_2.py

11 lines
306 B
Python
Raw Permalink Normal View History

2021-12-01 23:22:53 +00:00
import sys
2021-12-20 19:04:33 +00:00
L = list(map(int,sys.stdin.read().splitlines()))
2021-12-02 08:46:21 +00:00
print(sum([0,1][a<d] for (a,d) in zip(L, L[3:])))
# window1 = [A,B,C] ; window2 = [B,C,D]
# sum(Window1) <? sum(window2)
# (A+B+C) <? (B+C+D)
# (A+B+C)-B-C <? (B+C+D)-B-C
# A <? D
# eg: comparing A+B+C and B+C+D is the same as comparing A and D