-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6baeb5
commit 99689c1
Showing
4 changed files
with
26 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from typing import Any | ||
|
||
|
||
def puzzle(input: str) -> Any: | ||
groupedCalories = input.strip().split("\n\n") | ||
highest = 0 | ||
for group in groupedCalories: | ||
total = sum(int(calorie) for calorie in group.split("\n")) | ||
if total > highest: | ||
highest = total | ||
return highest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import heapq | ||
from typing import Any | ||
|
||
|
||
def puzzle(input: str) -> Any: | ||
groupedCalories = input.strip().split("\n\n") | ||
elvesCalories = [] | ||
for group in groupedCalories: | ||
elvesCalories.append(sum(int(calorie) for calorie in group.split("\n"))) | ||
# convert to negative to get 3 smallest using min heap | ||
elvesCalories = [-calories for calories in elvesCalories] | ||
heapq.heapify(elvesCalories) | ||
return sum(heapq.heappop(elvesCalories) * -1 for _ in range(3)) |
Empty file.