summaryrefslogtreecommitdiffstats
path: root/day3/__init__.py
diff options
context:
space:
mode:
authorGravatar Tom van der Lee <tom@vanderlee.io>2025-12-03 17:45:22 +0100
committerGravatar Tom van der Lee <tom@vanderlee.io>2025-12-03 17:45:22 +0100
commit89929901e88749c8428afd0cf5684caa49a246b7 (patch)
tree655ecbc45c6d1691e9d6f4c1411dbfd18cb5312c /day3/__init__.py
parent31a8d2b6b7da1fcf4992a1fa6190eb3c7dbc4000 (diff)
download2025-89929901e88749c8428afd0cf5684caa49a246b7.tar.gz
2025-89929901e88749c8428afd0cf5684caa49a246b7.tar.bz2
2025-89929901e88749c8428afd0cf5684caa49a246b7.zip
Day 3
Diffstat (limited to 'day3/__init__.py')
-rw-r--r--day3/__init__.py39
1 files changed, 39 insertions, 0 deletions
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 @@
1# -*- coding: utf-8 -*-
2from abc import ABC
3from typing import Iterator
4
5from aoc import BaseAssignment
6
7
8class Assignment(BaseAssignment, ABC):
9 @classmethod
10 def parse_item(cls, item: str) -> Iterator[list[int]]:
11 yield [int(i) for i in item]
12
13 @classmethod
14 def find_highest_joltage(cls, item: list[int], n: int) -> int:
15 values = list()
16 item_length = len(item)
17
18 last_index = -1
19 for end_index in range(item_length - n + 1, item_length + 1):
20 start_index = last_index + 1
21 value = max(item[start_index:end_index])
22 last_index = item.index(value, start_index, end_index)
23 values.append(str(value))
24
25 return int("".join(values))
26
27
28class AssignmentOne(Assignment):
29 example_result = 357
30
31 def run(self, input: Iterator[list[int]]) -> int:
32 return sum([self.find_highest_joltage(item, 2) for item in input])
33
34
35class AssignmentTwo(Assignment):
36 example_result = 3121910778619
37
38 def run(self, input: Iterator[list[int]]) -> int:
39 return sum([self.find_highest_joltage(item, 12) for item in input])