Day 1 - Advent of Code 2022

Working solutions for the day 1 puzzles.

Part One

""" day_01_01.py """

# usage: python3 day_01_01.py < input

most = 0
while True:
    total = 0
    try:
        while line := input():
            total += int(line)
    except EOFError:
        break
    finally:
        most = max(most, total)
print(most)

Part Two

""" day_01_02.py """

# usage: python3 day_01_02.py < input


def max3(value_list, value):
    """ calculate three highest values """
    values = value_list[:] + [value]
    values.sort(reverse=True)
    return values[:3]


most = [0, 0, 0]
while True:
    total = 0
    try:
        while line := input():
            total += int(line)
    except EOFError:
        break
    finally:
        most = max3(most, total)
print(sum(most))