This repository contains my own solutions to the Advent of Code coding puzzles.
Spoiler alert!
If you don't want those puzzles spoiled for you, don't look at the code!
It runs on Python 3.10+.
The puzzle-solving code is almost all purely Python Standard Library stuff. The only
required external dependency is numpy
.
numpy
There are also some optional dependencies to enable extra features:
rich
, for pretty printing on the consolepillow
, for rendering visualisationsnumba
, to speed up some of the number-crunchy solutionspytest
, to run the test suite
- Clone the repo
- Change into the top-level repo directory
- Execute
python3 -m venv .venv
to create a Python virtual environment - Execute
source .venv/bin/activate
to activate the virtual environment - Execute
pip install -r requirements.txt
to install all required and optional Python package dependencies
To simply run the solution for a puzzle, execute advent.py
at the top-level
of the repository, with the year and day number as positional arguments, for
example:
./advent.py 2023 9
You can give the -t/--test
argument to run the test case from the puzzle
explanation instead of the actual puzzle, -v/--verbose
to enable debug
logging, or -d/--draw
to output a visualisation (if the puzzle code supports
that).
You can also run ./advent.py
without any arguments to enter an interactive
mode which looks like this:
In the interactive mode, you can set up a new puzzle solution module from a template, add example inputs, download your actual inputs, toggle the visualisation and logging modes and run your solution in real or testing mode.
The interactive mode uses hot module loading, so in most cases you can re-run your solution after making changes without ever leaving interactive mode. The exceptions are when you make changes in another module that is imported by the solution, or you are changing functions that are under numba.jit compilation. In those cases you will need to exit and restart the interactive mode.
Here's a sample of some of the visualisations I generated for these puzzles, using my own custom animation rendering code, plus Pillow:
Using Breadth-first search (left) and A Star (right) to solve the maze.