33 lines
664 B
Python
Executable File
33 lines
664 B
Python
Executable File
#!/usr/bin/env python3
|
|
import sys
|
|
from typing import Sequence
|
|
|
|
|
|
def part1(lines: Sequence[int]):
|
|
inc = 0
|
|
last = lines[0]
|
|
for line in lines[1:]:
|
|
if line > last:
|
|
inc += 1
|
|
last = line
|
|
print(f"{inc} increments")
|
|
|
|
|
|
def part2(lines: Sequence[int]):
|
|
WINDOW_SIZE = 3
|
|
last = sum(lines[0:WINDOW_SIZE])
|
|
inc = 0
|
|
for i in range(1, len(lines) - WINDOW_SIZE + 1):
|
|
window = sum(lines[i:i+WINDOW_SIZE])
|
|
if window > last:
|
|
inc += 1
|
|
last = window
|
|
print(f"{inc} increments")
|
|
|
|
|
|
lines = [int(line) for line in sys.stdin if line]
|
|
print("Part 1")
|
|
part1(lines)
|
|
print("Part 2")
|
|
part2(lines)
|