From 89929901e88749c8428afd0cf5684caa49a246b7 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Wed, 3 Dec 2025 17:45:22 +0100 Subject: Day 3 --- day3/__init__.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 day3/__init__.py (limited to 'day3/__init__.py') diff --git a/day3/__init__.py b/day3/__init__.py new file mode 100644 index 0000000..9025f4a --- /dev/null +++ b/day3/__init__.py @@ -0,0 +1,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]) -- cgit v1.2.3