-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.py
57 lines (46 loc) · 2.94 KB
/
runner.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
54
55
56
57
import argparse, importlib, datetime
_today = datetime.date.today().day
def solve(day: int = -1, part: int = -1, optimal: bool = False, skip_test: bool = False, elapsed: bool = True, debug: bool = False):
try:
solution = importlib.import_module(f"solutions.{'optimal' if optimal else 'naive'}.day{day:02d}").Solver(skip_test, elapsed, debug).solve(part)
return solution
except:
if not 0 < day < 26: print("Day number must be between 1 and 25")
elif part not in [1, 2]: print("Part number must be 1 or 2")
else: print(f"There is no available {'optimal' if optimal else 'naive'} working solution for part {part} of day {day} yet.\n")
return None
def solve_all_until(day: int = min(_today, 25), optimal: bool = False, skip_test: bool = False, elapsed: bool = True, debug: bool = False):
solutions = {d:[] for d in range(1, day+1)}
for d in range(1, day+1):
print(f"# Day {d}:")
for p in [1,2]:
print(f"- Part {p}:")
solutions[d].append( solve(d, p, optimal, skip_test, elapsed, debug) )
print("-"*20)
return solutions
def solve_all(optimal: bool = False, skip_test: bool = False, elapsed: bool = True, debug: bool = False):
return solve_all_until(25, optimal, skip_test, elapsed, debug)
def main():
parser = argparse.ArgumentParser(description="Bulk runner of gabxcos' Advent of Code 2024 solutions")
parser.add_argument("-d", "--day", dest="day", default=_today, metavar="day_number", type=int, help="Required, day number of the AoC event")
parser.add_argument("-p", "--part", dest="part", default=1, metavar="part_number", type=int, help="Required, part number of the day of the AoC event")
parser.add_argument("--optimal", action="store_true", help="Optional, use the intended optimal solution instead of the one I actually came up with")
parser.add_argument("--skip-test", action="store_true", help="Optional, skipping tests")
parser.add_argument("--no-elapsed", action="store_true", help="Optional, avoid elapsed prints")
parser.add_argument("--debug", action="store_true", help="Optional, add debug prints and computations, if available")
parser.add_argument("--run-all", action="store_true", help="Optional, runs all available days with the given options; if set, -d and -p are ignored")
args = parser.parse_args()
if args.run_all:
solve_all_until(optimal=args.optimal, skip_test=args.skip_test, elapsed=not args.no_elapsed, debug=args.debug)
else:
if not 0 < args.day < 26:
print("Day number must be between 1 and 25")
exit()
elif args.part not in [1, 2]:
print("Part number must be 1 or 2")
exit()
else:
print(f"Solving day {args.day} part {args.part}:\n")
solve(day=args.day, part=args.part, optimal=args.optimal, skip_test=args.skip_test, elapsed=not args.no_elapsed, debug=args.debug)
if __name__=="__main__":
main()