Skip to content

Instantly share code, notes, and snippets.

@rtt
Last active December 3, 2022 13:57
Show Gist options
  • Select an option

  • Save rtt/b85c30211c5c5ed5bee99c964d4975a2 to your computer and use it in GitHub Desktop.

Select an option

Save rtt/b85c30211c5c5ed5bee99c964d4975a2 to your computer and use it in GitHub Desktop.

Revisions

  1. rtt renamed this gist Dec 3, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. rtt created this gist Dec 3, 2022.
    16 changes: 16 additions & 0 deletions aoc-2022-day1-.py
    Original 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])