This repository provides boilerplate code so you can jump straight into coding the challenges from the advent of code 2023
With pyenv and poetry installed, run the following commands, from the root of the repository, in this order:
- Install Python 3.12.1 with pyenv:
pyenv install 3.12.1
- Use pyenv to create a .python-version file that will be used by your shell if you installed pyenv correctly:
pyenv local 3.12.1
- Create a virtualenv, using the Python version installed above:
python3 -m venv .venv
- Activate the virtualenv created above:
source .venv/bin/activate
- Install other dependencies (linter, formatter, etc)
poetry install
Obs: Step #4 is the only one you'll need to repeat (from the root of the repo) after you close your terminal. The previous ones are one time only and the last one should only be repeated if you modify your
pyproject.toml
.
Part 1 of the first day is already implemented, to serve as an example.
Implement the solution to day N on advent2023/dN/__init__.py
. The directory for days 1-9 have a leading 0 as padding, but that 0 should not be provided on the command line, as shown below:
python3 advent2023 --day 1 --part 1 input/d01/part1_example.txt
If you prefer, you can instead redirect the input from stdin, e.g.:
python3 advent2023 --day 1 --part 1 < input/d01/part1_example.txt
The commands above don't work!
For the first day, the commands above should work even without pyenv and Poetry. You can try running it with -m
:
python3 -m advent2023 --day 1 --part 1 input/d01/part1_example.txt
Having that said, using the recommended pyenv
+Poetry
setup (remembering to activate your virtualenv, e.g., source .venv/bin/activate
) decreases the likelihood of conflicts with your system-wide python installation and its ecosystem.
If you're using Poetry, there are some nice commands to lint, format and clean your files (they assume your virtualenv location is .venv
, at the root of the project):
make all
make lint
make fmt
make clean
The entry point for every day/part is this file. It reads the command line options/arguments and accepts either an input file path directly or content from stdin. It imports the module that matches the provided day (e.g., advent2023.d08
for --day 8
), then calls either the part_1(lines)
or part_2(lines)
function of that module (both located in advent2023/dXX/__init__.py
)
In the file linked above, the default is to read the input and return a list of strings, one for each line. This might not be desirable for every day of the challenge. Since this repo is only a template to get started with the challenge, the modifications to parse input in a different manner are left as an exercise for the programmer 😉