-
Notifications
You must be signed in to change notification settings - Fork 0
/
01.py
25 lines (17 loc) · 803 Bytes
/
01.py
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
from pathlib import Path
def parse(input_contents: str) -> list[list[int]]:
inventories: list[str] = input_contents.strip().split("\n\n")
inventories_split: list[list[str]] = [inventory.split("\n") for inventory in inventories]
to_int = [list(map(int, inventory)) for inventory in inventories_split]
return to_int
def part_a(input_contents: str):
summed = [sum(inventory) for inventory in parse(input_contents)]
return max(summed)
def part_b(input_contents: str):
summed = [sum(inventory) for inventory in parse(input_contents)]
return sum(sorted(summed, reverse=True)[:3])
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
contents = Path("01_input.txt").read_text()
print(part_a(contents))
print(part_b(contents))