Advent of Code: 2024
- GitHub Repository: https://github.com/Tribruin/aoc2024/
First, create a repository on GitHub.
- Template: None (you don't need one!)
- Owner: "Tribruin"
- Repository Name: "aoc2024"
- Description: "Advent of Code: 2024"
- Visibility: Up to you. :)
You can leave the rest because we'll initialize these automatically in the next step.
Next, you can either execute the following in the root directory:
bash setup.sh
... or follow the rest of this README to do it manually. :)
Note: Don't blindly trust script files; go and look at it first. These are the exact instructions from this README.md
, but in a single script.
Then, run the following commands:
git init -b main
git add .
git commit -m "init: Advent of Code: 2024"
git remote add origin git@github.com:Tribruin/aoc2024.git
git push -u origin main --force
Note: Only pass --force
the first time you initialize; not every time!
Note: This assumes you're authenticating via ssh
and you're already setup.
Then, install the environment and the pre-commit hooks with
make install
This will also generate your uv.lock
file
Initially, the CI/CD pipeline might fail due to formatting issues. To resolve those run:
pre-commit run -a
Or, if you're outside of the devcontainer:
uv run pre-commit run -a
Lastly, commit the changes made by the two steps above to your repository.
git add -u
git commit -m 'fix: formatting'
git push origin main
You are now ready to solve Advent of Code in style, with extra swagger!
If you're using devcontainers, just execute code .
from the project directory, and you're almost ready.
When it loads, make sure you hit "Reopen in Container" in VSCode (at the bottom-right):
Yes, you have to do this everytime (but there are some shortcuts, like installing and using the devcontainer CLI).
Within your project folder, i.e., aoc2024/aoc2024, you've got a python file for each day you need to solve, such as 01.py
, as well as a corresponding input file, such as input/01.txt
.
You can update the code to solve the puzzle and put your input in the text file as per Advent of Code (feel free to skip checking it in if you want; a nice way to do that is to add aoc2024/aoc2024/input/*
to your .gitignore
file).
You've also got the following:
aoc2024/aoc2024/runner.py
: The CLI; check it out for arguments, or execute just the project with-h
.aoc2024/aoc2024/utils.py
: A utility file to get you started, but feel free to flesh it out. :)
The CLI will:
- Run your solution for all days or the days you specify (comma-separated list).
- Provide the answers you generated, either example or real, for each day.
- Provide CPU and timing information for each day.
- Provide Source Lines of Code (SLOC) and the number of characters for each day.
- Tell you whether it was a "golden" solution, i.e., it took less than one second.
- Tell you whether all together are "golden"; i.e., all took less than one second.
If you're in the devcontainer, just run the following:
python -m aoc2024
Or, if you're outside of the devcontainer:
uv run python -m aoc2024
If you'd like to redact the output (e.g., for sharing just timings elsewhere), execute the CLI with --redact
.
If you'd like to execute your tests, you can pass --test
to the CLI or execute pytest
.
If you're in the devcontainer, just run the following:
pytest
Or, if you're outside of the devcontainer:
uv run pytest
For everyone else who isn't @Tribruin: This repository was created using lskillen/cookiecutter-py-aoc, for a rockin' around the tree good time, developing Advent of Code solutions using Python+uv+ruff+mypy+pytest. Go there and find out how to get your own; yes, that means you!