Skip to content

Commit ba8fb7d

Browse files
authored
Y2025/day1 (#18)
* y2025d1 * copilot refactor * remove def * refactor to one solve function * update tests * refactor tests * save state
1 parent e764fd9 commit ba8fb7d

File tree

7 files changed

+4481
-1
lines changed

7 files changed

+4481
-1
lines changed

.github/copilot-instructions.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!-- Copilot / AI agent instructions for the advent-of-code-python repository -->
2+
3+
# How to be productive in this repository (short, specific)
4+
5+
This repo contains per-day Advent of Code solutions under `src/advent_of_code/year_<YYYY>/day_<NN>.py` with test cases under `tests/year_<YYYY>/test_day_<NN>.py` and input files in `inputs/year_<YYYY>/<NN>.dat`.
6+
7+
Follow these concrete rules and patterns when making changes or adding new solutions:
8+
9+
- Entrypoint contract: each day module should expose a function `main(input_file)` which accepts a path to the input file (string) and performs/prints the solution. `scripts/run_day.py` dynamically imports `advent_of_code.year_<year>.day_<NN>` and calls `main(input_file)`.
10+
- Input handling: use `src/advent_of_code/utils/input_handling.py::read_input(f)` to load inputs as a list of stripped lines. Input files live at `inputs/year_<YYYY>/<NN>.dat` and use zero-padded two-digit day names (e.g. `01.dat`).
11+
- Filenames & modules: code files are named `day_01.py`, `day_02.py`, etc. The module import path is `advent_of_code.year_2025.day_01` (note the zero padding in the module filename).
12+
- Tests & pytest: tests are under `tests/year_<YYYY>/test_day_<NN>.py`. The project config (pyproject.toml) sets `pythonpath = "src"` and `--import-mode=importlib`, so prefer importable modules and avoid relying on working-directory-only imports.
13+
14+
Quick commands (examples you can run locally):
15+
16+
- Run one day (example for year 2025 day 1):
17+
python3 scripts/run_day.py --year 2025 --day 1
18+
19+
- Run all discovered solutions (skips days without input files):
20+
python3 scripts/run_all_solutions.py
21+
22+
- Generate a new day + test from templates (templates in `scripts/templates`):
23+
python3 scripts/generate_new_day_skeleton_files_from_templates.py --year 2025 --day 1
24+
25+
- Run tests:
26+
pytest
27+
28+
Key files to inspect when changing behavior:
29+
30+
- `scripts/run_day.py` — dynamic import + `main(input_file)` invocation. If you change the `main` contract, update this script.
31+
- `scripts/run_all_solutions.py` — discovery logic: scans `src/advent_of_code` for `year_*` directories and filenames matching `day_\d{2}\.py`. It will skip running days with no corresponding `inputs/year_<YYYY>/<NN>.dat` file.
32+
- `src/advent_of_code/utils/input_handling.py` — canonical helpers for reading inputs and parsing simple formats used across days.
33+
- `scripts/generate_new_day_skeleton_files_from_templates.py` and `scripts/templates/*` — used to scaffold new day modules and tests; templates include `{day}` and `{year}` placeholders.
34+
- `pyproject.toml` — pytest configuration (`pythonpath=src`, `--import-mode=importlib`), black formatting, and build backend (hatchling). Use these settings when adding CI or packaging.
35+
36+
Project-specific conventions and gotchas (be precise):
37+
38+
- Zero-padding is significant: day files and input files are named with two-digit zero padding (e.g., `day_01.py``01.dat`). `run_day.py` zero-pads the provided `--day` argument.
39+
- `run_all_solutions.py` relies on simple `os.listdir` ordering; do not assume nested directories beyond `src/advent_of_code/year_<YYYY>/`.
40+
- The repo uses `python3` in scripts; local development should use a Python 3.8+ interpreter (pyproject says >=3.8). Black config targets Python 3.9 but code is compatible with 3.8+.
41+
- Tests import the package from `src/` via pytest config. When editing tests or modules, ensure the module path `advent_of_code.year_<YYYY>.day_<NN>` is importable.
42+
43+
Small implementation checklist for a new/updated day module:
44+
45+
1. Create `src/advent_of_code/year_<YYYY>/day_<NN>.py` using templates or follow the `main(input_file)` contract.
46+
2. Add `inputs/year_<YYYY>/<NN>.dat` (zero-padded).
47+
3. Add/verify `tests/year_<YYYY>/test_day_<NN>.py` follows existing test style.
48+
4. Use `utils.read_input` where appropriate to keep input parsing consistent.
49+
5. Run `python3 scripts/run_day.py --year <YYYY> --day <N>` and `pytest`.
50+
51+
If you need to change a project-wide behavior (import rules, test config, discovery), update `pyproject.toml` and the scripts above; prefer small, backward-compatible changes because many scripts dynamically import day modules.
52+
53+
If anything here is unclear or you'd like the instructions to be stricter (for example, enforcing a return value contract instead of printing), tell me which style you'd prefer and I will update this file.

0 commit comments

Comments
 (0)