Last active
December 3, 2022 13:57
-
-
Save rtt/b85c30211c5c5ed5bee99c964d4975a2 to your computer and use it in GitHub Desktop.
Revisions
-
rtt renamed this gist
Dec 3, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
rtt created this gist
Dec 3, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ def run(): with open('./input.txt') as f: data = f.read() calorie_counts = {} for elf, calories in enumerate(data.split('\n\n'), start=1): calorie_counts[elf] = sum(map(int, calories.strip().split('\n'))) # part 1 print(calorie_counts[max(calorie_counts, key=calorie_counts.get)]) # part 2 top_3 = list({k: v for k, v in sorted(calorie_counts.items(), key=lambda x: x[1])}.items())[-3:] print(sum([v for k, v in top_3])