Sean McLemon | Advent of Code

Home | Czech | Blog | GitHub | Advent Of Code | Notes


2022-12-01 - Calorie Counting

(original .ipynb)

Day 1 puzzle input is groups of integers which represent "calories" of food some elves can carry (mine is here). Part 1 involves finding the elf who can carry the most. Part two is finding the sum of how much the top-three elves can carry.

puzzle_input_str = open("puzzle_input/day1.txt").read()

def parse_elves(input_str):
    return sorted([
            sum([int(s) for s in elf_load.split("\n")])
            for elf_load in input_str.split("\n\n")
        ], reverse=True)


def part_one(input_str):
    elves = parse_elves(input_str)
    return elves[0]
    

print("part one:", part_one(puzzle_input_str))
part one: 71023
def part_two(input_str):
    elves = parse_elves(input_str)
    return sum(elves[:3])

    
print("part two:", part_two(puzzle_input_str))
part two: 206289