mirror of
https://github.com/chylex/Advent-of-Code.git
synced 2025-06-03 00:34:04 +02:00
Add 2022 - Day 1 - Part 2
This commit is contained in:
parent
fb795c2a38
commit
91339c9d02
@ -6,7 +6,12 @@ lines = read_input()
|
|||||||
groups = [list(group) for is_group, group in groupby(lines, lambda x: x != '') if is_group]
|
groups = [list(group) for is_group, group in groupby(lines, lambda x: x != '') if is_group]
|
||||||
|
|
||||||
carrying_calories = ((int(item) for item in group) for group in groups)
|
carrying_calories = ((int(item) for item in group) for group in groups)
|
||||||
carrying_total_calories = (sum(group) for group in carrying_calories)
|
carrying_total_calories = [sum(group) for group in carrying_calories]
|
||||||
most_calories_carried = max(carrying_total_calories)
|
most_calories_carried = max(carrying_total_calories)
|
||||||
|
|
||||||
print(f"Most calories carried: {most_calories_carried}")
|
print(f"Most calories carried: {most_calories_carried}")
|
||||||
|
|
||||||
|
top3_most_calories_carried = sorted(carrying_total_calories, reverse=True)[:3]
|
||||||
|
top3_most_calories_carried_total = sum(top3_most_calories_carried)
|
||||||
|
|
||||||
|
print(f"Total calories carried by the top 3: {top3_most_calories_carried_total}")
|
||||||
|
Loading…
Reference in New Issue
Block a user