from abc import ABC from itertools import groupby from typing import Iterator, Any, List from aoc import BaseAssignment class Assignment(BaseAssignment, ABC): def calculate_elf_calories(self, input: Iterator) -> List[int]: return [ sum([ int(i) for i in group ]) for in_group, group in groupby(input, key=bool) if in_group ] class AssignmentOne(Assignment): example_result = 24000 def run(self, input: Iterator) -> int: return max(self.calculate_elf_calories(input)) class AssignmentTwo(Assignment): example_result = 45000 def run(self, input: Iterator) -> int: return sum( sorted( self.calculate_elf_calories(input), reverse=True )[:3] )