-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
53 lines (40 loc) · 1.43 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import importlib
import sys
from data_parser import load_file
from logger_config import logger
YEAR = "2024"
def run_solution(day, part, input_data):
try:
solution = getattr(day, f"part{part}")(input_data)
logger.info(f"Solution for {day.__name__} part {part}: {solution}")
except AttributeError as e:
logger.warning(f"Solution function for {day.__name__} part {part} not found.")
return
def main():
if len(sys.argv) < 2 or len(sys.argv) > 3:
logger.info("Usage: python run.py <day_number> [part_number]")
return
day = sys.argv[1]
part = sys.argv[2] if len(sys.argv) == 3 else None
# Ensure day is in the correct format
day_module_name = f"day_{int(day):02d}"
# Read the corresponding input file
try:
data = load_file(f"inputs/year_{YEAR}/{day_module_name}.txt")
except FileNotFoundError:
logger.warning(f"Input file for {day_module_name} not found.")
return
# Dynamically import the day module from the correct year package
try:
module = importlib.import_module(f"solutions.year_{YEAR}.{day_module_name}")
except ModuleNotFoundError as e:
logger.warning(f"Module for {day_module_name} not found.")
return e
if part:
run_solution(module, part, data)
else:
# Run both parts
for part in [1, 2]:
run_solution(module, part, data)
if __name__ == "__main__":
main()