diff options
Diffstat (limited to 'aoc')
| -rw-r--r-- | aoc/__init__.py | 12 |
1 files changed, 11 insertions, 1 deletions
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): | |||
| 16 | def parse_item(self, item: str) -> Any: | 16 | def parse_item(self, item: str) -> Any: |
| 17 | return item | 17 | return item |
| 18 | 18 | ||
| 19 | @property | ||
| 20 | def part(self): | ||
| 21 | return 1 if self.__class__.__name__.endswith("One") else 2 | ||
| 22 | |||
| 19 | def read_input(self, example=False) -> Generator: | 23 | def read_input(self, example=False) -> Generator: |
| 20 | file = f"{self.path}/input.txt" | 24 | file = f"{self.path}/input.txt" |
| 25 | |||
| 21 | if example or not os.path.isfile(file): | 26 | if example or not os.path.isfile(file): |
| 22 | file = f"{self.path}/example.txt" | 27 | for file in [ |
| 28 | f"{self.path}/example_part_{self.part}.txt", | ||
| 29 | f"{self.path}/example.txt", | ||
| 30 | ]: | ||
| 31 | if os.path.exists(file): | ||
| 32 | break | ||
| 23 | 33 | ||
| 24 | with open(file, "r") as input_file: | 34 | with open(file, "r") as input_file: |
| 25 | for line in input_file.readlines(): | 35 | for line in input_file.readlines(): |
