From 0af1b042a29811bc5c850267681dc45469981845 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Mon, 12 Dec 2022 08:51:41 +0100 Subject: Day 9 [WIP] --- aoc/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'aoc/__init__.py') diff --git a/aoc/__init__.py b/aoc/__init__.py index 3662e3a..8368f7b 100644 --- a/aoc/__init__.py +++ b/aoc/__init__.py @@ -16,10 +16,20 @@ class BaseAssignment(ABC): def parse_item(self, item: str) -> Any: return item + @property + def part(self): + return 1 if self.__class__.__name__.endswith("One") else 2 + 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" + for file in [ + f"{self.path}/example_part_{self.part}.txt", + f"{self.path}/example.txt", + ]: + if os.path.exists(file): + break with open(file, "r") as input_file: for line in input_file.readlines(): -- cgit v1.2.3