26 lines
532 B
Python
26 lines
532 B
Python
from pathlib import Path
|
|
|
|
|
|
def parse_input(data: str) -> list[int]:
|
|
result = []
|
|
for group in data.split("\n\n"):
|
|
result.append(sum([int(line) for line in group.split()]))
|
|
|
|
return result
|
|
|
|
|
|
# Setup
|
|
data = (Path(__file__).parents[1] / "input").read_text()
|
|
|
|
# Problem solving - part 1
|
|
calories = parse_input(data)
|
|
max_calories = max(calories)
|
|
|
|
print(f"Part 1 answer: {max_calories}")
|
|
|
|
# Problem solving - part 2
|
|
top_3 = sorted(calories, reverse=True)[:3]
|
|
top_3_sum = sum(top_3)
|
|
|
|
print(f"Part 2 answer: {top_3_sum}")
|