Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Advent of Code/2022/Day 1/day1.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ def parse(file):


def part_1(lst):
print(f'The total number of calories that the elf is carrying is: {max([sum(ele) for ele in lst])}')
print(
f'The total number of calories that the elf is carrying is: {max(sum(ele) for ele in lst)}'
)
Comment on lines -16 to +18
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function part_1 refactored with the following changes:



def part_2(lst):
res, num_max = 0, 3
sums_heap = [-1 * sum(ele) for ele in lst]
heapq.heapify(sums_heap)
for i in range(num_max):
for _ in range(num_max):
Comment on lines -23 to +25
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function part_2 refactored with the following changes:

res += -1 * heapq.heappop(sums_heap)
print(f'The total number of calories that the elves are carrying is: {res}')

Expand Down