diff options
| author | 2022-12-12 08:51:41 +0100 | |
|---|---|---|
| committer | 2022-12-12 08:51:41 +0100 | |
| commit | 0af1b042a29811bc5c850267681dc45469981845 (patch) | |
| tree | 45c22e15c932fac2e56a20b17207a8048d28f7b4 /aoc | |
| parent | cdd7aec2e28e65886c02bf2729bc8d2032f0ef6e (diff) | |
| download | 2022-0af1b042a29811bc5c850267681dc45469981845.tar.gz 2022-0af1b042a29811bc5c850267681dc45469981845.tar.bz2 2022-0af1b042a29811bc5c850267681dc45469981845.zip | |
Day 9 [WIP]
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(): |
