Python: Solved day 1 and 2
This commit is contained in:
25
01/py/solution.py
Normal file
25
01/py/solution.py
Normal file
@@ -0,0 +1,25 @@
|
||||
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}")
|
||||
Reference in New Issue
Block a user