From a3de698aa6b7e15e9d0974d32dc566676383bd28 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Mon, 28 Nov 2022 13:52:27 +0100 Subject: Initial code --- aoc/__init__.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 aoc/__init__.py (limited to 'aoc/__init__.py') diff --git a/aoc/__init__.py b/aoc/__init__.py new file mode 100644 index 0000000..b13489c --- /dev/null +++ b/aoc/__init__.py @@ -0,0 +1,27 @@ +import os +from abc import ABC +from typing import Generator, Any, Iterator + + +class BaseAssignment(ABC): + example_result = NotImplemented + def __init__(self, path): + self.path = path + + def __str__(self): + return f'{self.__module__}.{self.__class__.__name__}' + + def parse_item(self, item: str) -> Any: + return item + + def read_input(self, example = False) -> Generator: + file = f'{self.path}/input.txt' + if example or not os.path.isfile(file): + file = f'{self.path}/example.txt' + + with open(file, 'r') as input_file: + for line in input_file.readlines(): + yield self.parse_item(line.strip()) + + def run(self, input: Iterator) -> Any: + raise NotImplementedError('Please implement run') \ No newline at end of file -- cgit v1.2.3