summaryrefslogtreecommitdiffstats
path: root/day1/__init__.py
blob: bc44089a78e404a171b467750b4723f2a337120c (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
from typing import Iterator, List

from aoc import BaseAssignment


class Assignment(BaseAssignment):
    def parse_item(self, item: str) -> int:
        return int(item)

    def read_input(self, example = False) -> List[int]:
        return list(super().read_input(example))

class AssignmentOne(Assignment):
    def run(self, input: List) -> int:
        result = 0

        for i in range(1, len(input)):
            result += 1 if input[i - 1] < input[i] else 0

        return result


class AssignmentTwo(Assignment):
    def run(self, input: List) -> int:
        new_input = [
            input[i - 2] + input[i - 1] + input[i]
            for i in range(2, len(input))
        ]

        return AssignmentOne(path='').run(new_input)