|
@@ -1,17 +1,10 @@
|
|
|
import util
|
|
|
+from more_itertools.recipes import sliding_window as sw
|
|
|
|
|
|
-def sliding_window(input, size=1):
|
|
|
- count = 0
|
|
|
- current = input[0:size]
|
|
|
-
|
|
|
- for i in input[size:]:
|
|
|
- next = current[1:] + [i]
|
|
|
- if sum(next) > sum(current):
|
|
|
- count += 1
|
|
|
- current = next
|
|
|
+input = util.get_input("1.input", int)
|
|
|
|
|
|
- return count
|
|
|
+def day_1(input, size):
|
|
|
+ return len([1 for [a, b] in sw(sw(input, size), 2) if sum(a) < sum(b)])
|
|
|
|
|
|
-input = util.get_input("1.input", int)
|
|
|
-print(sliding_window(input, 1))
|
|
|
-print(sliding_window(input, 3))
|
|
|
+print(day_1(input, 1))
|
|
|
+print(day_1(input, 3))
|