https://adventofcode.com/2021. I may keep some notes here on the more interesting problems.
Solutions are labeled XXY
for problem XX
("01" through "25"), part Y
(either "a" or "b").
All solutions must be run from the top-level repo directory, with input on stdin, and will print the answer as the final
line of output (
additional lines of debug/info may be printed before; pipe into tail -n1
to get only the answer).
All Go solutions are compiled into a single executable, the top-level package. To run solution XXY
:
$ go run . XXY
For example: go run . 01a <inputs/1.input
There is one JQ script per problem part. jq
must be installed to run; to install on Mac with Brew,
use brew install jq
.
There are two ways to run solution XXY
:
This is the preferred method, assuming your system has /usr/bin/env
that can find jq
(Brew ensures this). Just run:
$ pXX/pXXY.jq
For example: p01/p01a.jq <inputs/1.input
First, open the JQ script file and copy all of the flags from the hashbang. For example, p02a.jq
has:
#!/usr/bin/env jq -s -R -f
so your flags are -s -R -f
. Then, run jq
as follows:
$ jq [flags] pXX/pXXY.jq
For example: jq -s -R -f p02/p02a.jq <inputs/2.input
These tools help speed up running/testing a solution. They're designed for Mac; YMMV on other platforms.
To load tools for problem X (note: single digit X
for problems 1โ9), run:
$ . aoc.sh X
For example: . aoc.sh 1
This makes available the following bash functions, all acting for problem X
:
$ get # downloads main input as inputs/X.input, and the Z'th code block from problem as inputs/XY.sampleZ.input
$ samp[jq] Y [Z] # runs Go (JQ) solution for part Y on code block Z (default 0)
$ run[jq] Y # runs Go (JQ) solution for part Y on main input (copies last output line to clipboard)
A typical sequence would go:
$ get # download inputs
# ... write part A solution ...
$ samp a # test part A; repeat as needed
$ run a # run part A "for real"; repeat as needed, then paste answer to website
# ... repeat for part B ...
The solution templates (Go and JQ) were generated by running setup/setup.sh
from the top repo directory.