These are my solutions for the puzzles of Advent of Code. I enjoy writing code in TypeScript, so that’s what I used. This repository contains everything you need to run my solutions.
The solutions require NodeJS version 22.1.0 to run. In addition, you need a few packages; these can be installed by running the pnpm install command from the root folder of the project.
Challenges are grouped per year, in a folder named after the full year. Each year folder contains a directory for each day, named using two-digit numbers. For example, the solution for the challenge of December 9, 2015 can be found in 2015/09.
By default, running a solution will download the challenge input if there is no input.txt present in the solution folder. To download the challenge input, your session ID for the Advent of Code website is required.
To get your session ID cookie, visit the Advent of Code website and log in. Using your browser’s inspector, find the value of the session cookie.
This value needs to be inserted into a .env file that you create in the root folder of the project. See the .env.example file for an example.
There is a scaffold available that sets up the basics for a solution for a specific day. To scaffold a day, run the following command from the terminal:
pnpm scaffold <year>/<day>For example, to scaffold the solution for day 1 of 2015, run:
pnpm scaffold 2015/1To run a solution, use the following command:
pnpm solve <year>/<day>/<part>For instance, to run the solution for day 2, part 1:
pnpm solve 2015/2/1Each solution requires the puzzle input. When there is no input.txt file in the day folder, the input will be downloaded from the Advent of Code website. Because the input differs per account, a session ID cookie is needed. See the Advent of Code session ID section for instructions on setting the session ID.
If you want to use custom input instead, you can create an input.txt file yourself and populate it with whatever data you want to use.
If you want to see how fast a given solution runs, there is a measurement script that benchmarks it. It will run the solution multiple times and report the fastest and slowest runs, as well as the median and average execution times.
To run the benchmark, execute:
pnpm measure <year>/<day>/<part>To benchmark the solution for part 2 of day 1 in 2015:
pnpm measure 2015/1/2By default, the script will run the solution 50 times. You can specify a different sample size by adding a second parameter. The following command will take 75 samples:
pnpm measure 2015/1/2 75