mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-26 21:30:31 +01:00
Better project setup, now with a structure UV likes
This commit is contained in:
44
2024/src/aoc/days/__init__.py
Normal file
44
2024/src/aoc/days/__init__.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import importlib
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any, cast
|
||||
|
||||
|
||||
class Runner(ABC):
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def run_both(cls, data: str) -> tuple[Any, Any]:
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def part1(cls, data: str) -> Any:
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def part2(cls, data: str) -> Any:
|
||||
pass
|
||||
|
||||
|
||||
class SeparateRunner(Runner):
|
||||
@classmethod
|
||||
def run_both(cls, data: str) -> tuple[Any, Any]:
|
||||
return (cls.part1(data), cls.part2(data))
|
||||
|
||||
|
||||
class CombinedRunner(Runner):
|
||||
@classmethod
|
||||
def part1(cls, data: str) -> Any:
|
||||
return cls.run_both(data)[0]
|
||||
|
||||
@classmethod
|
||||
def part2(cls, data: str) -> Any:
|
||||
return cls.run_both(data)[1]
|
||||
|
||||
|
||||
def get_runner(day: int) -> type[Runner]:
|
||||
runner_module = importlib.import_module(f".day{day}", package=__name__)
|
||||
|
||||
assert issubclass(runner_module.DayRunner, Runner)
|
||||
|
||||
return cast(type[Runner], runner_module.DayRunner)
|
||||
13
2024/src/aoc/days/day1.py
Normal file
13
2024/src/aoc/days/day1.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from typing import Any
|
||||
|
||||
from . import SeparateRunner
|
||||
|
||||
|
||||
class DayRunner(SeparateRunner):
|
||||
@classmethod
|
||||
def part1(cls, _data: str) -> Any:
|
||||
return "Hello"
|
||||
|
||||
@classmethod
|
||||
def part2(cls, _data: str) -> Any:
|
||||
return "world!"
|
||||
Reference in New Issue
Block a user