# -*- coding: utf-8 -*- from abc import ABC from typing import Iterator from aoc import BaseAssignment class Assignment(BaseAssignment, ABC): @classmethod def parse_item(cls, item: str) -> Iterator[list[int]]: yield [int(i) for i in item] @classmethod def find_highest_joltage(cls, item: list[int], n: int) -> int: values = list() item_length = len(item) last_index = -1 for end_index in range(item_length - n + 1, item_length + 1): start_index = last_index + 1 value = max(item[start_index:end_index]) last_index = item.index(value, start_index, end_index) values.append(str(value)) return int("".join(values)) class AssignmentOne(Assignment): example_result = 357 def run(self, input: Iterator[list[int]]) -> int: return sum([self.find_highest_joltage(item, 2) for item in input]) class AssignmentTwo(Assignment): example_result = 3121910778619 def run(self, input: Iterator[list[int]]) -> int: return sum([self.find_highest_joltage(item, 12) for item in input])