diff options
Diffstat (limited to 'aoc/__init__.py')
| -rw-r--r-- | aoc/__init__.py | 24 |
1 files changed, 24 insertions, 0 deletions
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 @@ | |||
| 1 | import os | ||
| 2 | from abc import ABC | ||
| 3 | from collections import Iterator | ||
| 4 | from typing import Generator, Any | ||
| 5 | |||
| 6 | |||
| 7 | class AssignmentBase(ABC): | ||
| 8 | def __init__(self, path): | ||
| 9 | self.path = path | ||
| 10 | |||
| 11 | def parse_item(self, item: str) -> Any: | ||
| 12 | return item | ||
| 13 | |||
| 14 | def read_input(self, example = False) -> Generator: | ||
| 15 | file = f'{self.path}/input.txt' | ||
| 16 | if example or not os.path.isfile(file): | ||
| 17 | file = f'{self.path}/example.txt' | ||
| 18 | |||
| 19 | with open(file, 'r') as input_file: | ||
| 20 | for line in input_file.readlines(): | ||
| 21 | yield self.parse_item(line.strip()) | ||
| 22 | |||
| 23 | def run(self, input: Iterator) -> Any: | ||
| 24 | raise NotImplementedError('Please implement run') | ||
