-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
44 lines (31 loc) · 931 Bytes
/
main.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
"""Puzzle Solver Runner."""
import importlib
import click
from aocd import get_data
from utils.cli import DAY
from utils.cli import PART
from utils.cli import YEAR
class Solver:
"""Main app class."""
@staticmethod
def main(year: int, day: int, part: str) -> None:
"""Print the result to a console."""
task = get_data(day=day, year=year)
solver = importlib.import_module(f"src.year{year}.day{day:02}{part}")
solution = solver.solve(task) # type: ignore
print("Answer:", solution)
@click.group()
@click.pass_context
def cli(ctx):
"""Solve Advent of Code puzzles."""
ctx.obj = Solver()
@cli.command()
@click.argument("year", type=YEAR)
@click.argument("day", type=DAY)
@click.argument("part", type=PART)
@click.pass_obj
def solve(solver, year, day, part):
"""Solve the given puzzle."""
solver.main(year, day, part)
if __name__ == "__main__":
cli()