Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions .github/workflows/2019.yml

This file was deleted.

52 changes: 0 additions & 52 deletions .github/workflows/2023.yml

This file was deleted.

43 changes: 43 additions & 0 deletions .github/workflows/2024.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
on:
- push

name: Advent of Code 2024

jobs:
ci:
strategy:
matrix:
python-version:
- "3.12"
- "3.13"

name: Continuous Integration
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: "2024/uv.lock"

- name: Check formatting
working-directory: "2024"
run: >
uv run ruff format --check

- name: Run lints
working-directory: "2024"
run: >
uv run ruff check

- name: Run tests
working-directory: "2024"
run: >
uv run pytest tests
Empty file added 2024/README.md
Empty file.
26 changes: 26 additions & 0 deletions 2024/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[project]
name = "aoc-2024"
version = "0.1.0"
description = "Advent of Code 2024 solutions programs"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"click>=8.1.7",
"numpy>=2.1.2",
]

[dependency-groups]
dev = [
"mypy>=1.13.0",
"pytest>=8.3.3",
"ruff>=0.7.3",
]

[tool.uv]
package = true

[tool.ruff.lint]
select = ["F", "E", "I"]

[tool.mypy]
strict = true
Empty file added 2024/src/aoc/__init__.py
Empty file.
39 changes: 39 additions & 0 deletions 2024/src/aoc/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import datetime
import time

import click

from aoc import days


@click.command()
@click.option(
"-i",
"--input",
"data",
type=click.File(mode="rt", encoding="utf8"),
default="-",
help="Problem input file",
)
@click.option(
"-t", "--time", "timing", is_flag=True, help="Print elapsed time afterwards"
)
@click.argument("day", required=True)
def main(day: int, timing: bool, data: str) -> None:
runner_class = days.get_runner(day)

start = time.perf_counter_ns()

part1, part2 = runner_class.run_both(data)

if timing:
elapsed = time.perf_counter_ns() - start
delta = datetime.timedelta(microseconds=elapsed / 1000)
click.echo(f"Elapsed: {delta}", err=True)

click.echo(part1)
click.echo(part2)


if __name__ == "__main__":
main()
44 changes: 44 additions & 0 deletions 2024/src/aoc/days/__init__.py
Original file line number Diff line number Diff line change
@@ -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 changes: 13 additions & 0 deletions 2024/src/aoc/days/day1.py
Original file line number Diff line number Diff line change
@@ -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!"
6 changes: 6 additions & 0 deletions 2024/tests/test_harness.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from aoc import days


def test_harness_works() -> None:
runner = days.get_runner(1)
assert runner is not None
Loading