summaryrefslogtreecommitdiffstats
path: root/day3/__init__.py
blob: 9025f4a351e5052c3aaf3d798752aa763fc42269 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*- 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])