|
1 | 1 | from importlib import import_module |
2 | 2 |
|
3 | 3 |
|
4 | | -def initialise(day: int): |
| 4 | +def initialise(day: int, skip_test: bool = True): |
5 | 5 | """ |
6 | 6 | Dynamically load and instantiate the `Solution` class for a specific puzzle day. |
7 | 7 |
|
8 | | - Creates a `Solution` instance for the specified day by dynamically importing |
9 | | - the appropriate module from the solutions package. |
10 | | -
|
11 | 8 | Args: |
12 | 9 | day (int): The day number (1-25) of the puzzle to initialize. |
| 10 | + skip_test (bool, optional): Whether to skip test input and use puzzle input. |
| 11 | + Defaults to True. |
13 | 12 |
|
14 | 13 | Returns: |
15 | | - Solution: An instance of the day's `Solution` class, initialized with the day number. |
| 14 | + Solution: An instance of the day's `Solution` class, initialized with the |
| 15 | + specified parameters. |
16 | 16 |
|
17 | 17 | Note: |
18 | 18 | - Expects solution modules to be named `dayXX.py` where `XX` is zero-padded day number |
19 | 19 | - Expects each solution module to have a `Solution` class |
20 | 20 | - Solution modules should be in the `solutions` package |
21 | | - - Solution class must accept `day` parameter in constructor |
| 21 | + - Solution class must accept `day` and `skip_test` parameters in constructor |
22 | 22 |
|
23 | 23 | Example: |
24 | | - >>> solution = initialise(1) |
25 | | - # Imports `solutions.day01` and returns `Solution(day=1)` |
| 24 | + >>> solution = initialise(1) # Uses puzzle input |
| 25 | + >>> test_solution = initialise(1, skip_test=False) # Uses test input |
26 | 26 | """ |
27 | | - # Dynamically import the solution module based on the day |
28 | 27 | module_name = f"solutions.day{day:02d}" |
29 | 28 | solution_module = import_module(module_name) |
30 | | - |
31 | | - # Get the `Solution` class |
32 | 29 | Solution = getattr(solution_module, "Solution") |
33 | 30 |
|
34 | | - # Instantiate and return the `Solution` object |
35 | | - return Solution(day=day) |
| 31 | + return Solution(day=day, skip_test=skip_test) |
0 commit comments