Skip to content

Instantly share code, notes, and snippets.

@rtt
Last active December 3, 2022 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtt/b85c30211c5c5ed5bee99c964d4975a2 to your computer and use it in GitHub Desktop.
Save rtt/b85c30211c5c5ed5bee99c964d4975a2 to your computer and use it in GitHub Desktop.
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])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment