From 4985ee94450df0bbcf982b7652c946a47707e60c Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Fri, 11 Dec 2020 23:53:45 +0100 Subject: Added AoC day 1 and 2 --- aoc/__init__.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 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..b07ead1 --- /dev/null +++ b/aoc/__init__.py @@ -0,0 +1,24 @@ +import os +from abc import ABC +from collections import Iterator +from typing import Generator, Any + + +class AssignmentBase(ABC): + def __init__(self, path): + self.path = path + + 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') -- cgit v1.2.3