-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday01.py
More file actions
28 lines (22 loc) · 804 Bytes
/
Copy pathday01.py
File metadata and controls
28 lines (22 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from rich.console import Console
from typing import List
def count_increases_for_window(numbers: List[int], window_size: int) -> int:
increases = 0
window = []
prevSum = None
for number in numbers:
if len(window) == window_size:
window.pop(0)
window.append(number)
if prevSum and sum(window) > prevSum:
increases += 1
if len(window) == window_size:
prevSum = sum(window)
return increases
console = Console()
with open("day01.txt", "r") as file:
console.print("[b yellow]Day 01 - part 1[/b yellow]")
numbers = [int(x) for x in file.readlines()]
print(count_increases_for_window(numbers, 1))
console.print("[b yellow]Day 02 - part 2[/b yellow]")
print(count_increases_for_window(numbers, 3))