Clojure based AOC helper.
This is a set of scripts which will help you work on Advent Of Code puzzles.
Specifically it will help you:
This framework also supports having multiple years together in the same repository. Your session for each year is different so you will need to add an auth for each year you want to use.
Before you use this framework there is a pre-requisite of babashka
On a mac you can install babashka using brew:
$ brew install babashka
For other installation instructions see the official docs
In an empty folder, run:
$ bb -Sdeps '{:deps {io.github.jjcomer/aoc-clj-elf {:mvn/version "0.3.0"}}}' -m aoc-clj-elf.core init
This creates:
bb.edn with the library as a dependency and a single aoc task.gitignore covering auth.edn (your session token) and input/ (AoC asks that puzzle inputs not be shared publicly)src/ for your solutionsRunning it in an existing folder is safe: existing files are left alone, and any missing .gitignore entries are appended. If you would rather set things up by hand, the generated bb.edn is:
{:paths ["src"]
:deps {io.github.jjcomer/aoc-clj-elf {:mvn/version "0.3.0"}}
:tasks {aoc {:doc "Advent of Code helper. Try: bb aoc help"
:requires ([aoc-clj-elf.core :as aoc])
:task (apply aoc/-main *command-line-args*)}}}
Every command then runs through that one task, for example bb aoc solve. Run bb aoc help to list the commands. New commands arrive with library upgrades, with no changes to bb.edn needed. If you would like more dependencies for your solutions, add them to :deps.
You can also skip the task and run bb -m aoc-clj-elf.core <command>.
Your existing bb.edn with one task per command (bb get, bb solve, ...) keeps working. To switch to the single task, replace your :tasks with the aoc task above.
Every puzzle command takes :year and :day. When left out:
:year defaults to the current year during December, otherwise last year's event:day defaults to today's puzzle while the event is running. Outside the event you need to pass :daySince 2025, AoC has 12 puzzles per event instead of 25, and the commands check for this.
In order to be able to pull input for your puzzles you will need to provide your AOC session cookie value from your browser.
To find it:
Cmd+Option+I on macOS, F12 on Windows/Linux)https://adventofcode.comsession cookieTreat this value like a password: anyone who has it can act as you on AoC.
Once you have your token, you will need to store the value for the scripts to use. This is done using the auth command:
$ bb aoc auth --year <YEAR> --session <SESSION TOKEN>
If you don't specify a year, the script will assume the current year. You can store session tokens for multiple years within the same repo.
Session tokens are stored within the auth.edn file at the root of the repo. Make sure it is in your .gitignore to prevent accidental check-ins. On macOS/Linux it is created readable by your user only.
AoC asks that automated tools say who is making requests. You can add your own contact details to the User-Agent by adding a :user-agent entry to auth.edn:
{2026 "<SESSION>"
:user-agent "github.com/<you>/<your-aoc-repo> by <you>@example.com"}
If downloading input fails with an error like PKIX path building failed or unable to find valid certification path to requested target, something between you and adventofcode.com is presenting a certificate that babashka doesn't trust. This is usually a corporate proxy or VPN that inspects TLS traffic and re-signs it with the company's own root certificate.
Do not work around this by turning off certificate checking. The scripts send your session cookie with every request, and without certificate checks anyone who can intercept your traffic could read it. Instead, tell babashka to trust your company's root certificate:
Export your company's root CA certificate as a .pem/.crt file. Your IT team can usually provide it. On macOS you can also export it from Keychain Access (find it under System or System Roots, then File → Export Items…, choosing the .pem format).
Create a trust store that contains both the standard public CAs and your company's CA. keytool comes with any JDK:
# Start from the JDK's default CA bundle so normal sites keep working
$ cp "$(/usr/libexec/java_home)/lib/security/cacerts" ~/.java-truststore.p12 # macOS
# (Linux: copy $JAVA_HOME/lib/security/cacerts instead)
# Add your company's root CA
$ keytool -importcert -noprompt \
-alias corporate-root-ca \
-file /path/to/corporate-root-ca.pem \
-keystore ~/.java-truststore.p12 \
-storepass changeit
Point babashka at the trust store. Babashka accepts Java system properties as -D flags, so add a wrapper to your ~/.zshrc or ~/.bashrc:
bb () {
command bb -Djavax.net.ssl.trustStore="$HOME/.java-truststore.p12" \
-Djavax.net.ssl.trustStorePassword=changeit "$@"
}
Open a new shell (or source the file), then run bb aoc get again.
To check whether the proxy is the cause, run curl -v https://adventofcode.com 2>&1 | grep issuer. If the issuer is your company rather than a public CA such as Let's Encrypt, the proxy is re-signing the traffic.
When your company's root CA is renewed, re-run the keytool import with the new certificate.
When you are ready to start solving a problem the framework can generate a starting file for you to use and which will be compatible with the included runners.
To create a new solution file execute the new command:
$ bb aoc new --year <YEAR> --day <DAY>
This will create a new file under src/y<YEAR>/d<DAY>.clj
Your puzzle input can be downloaded directly from AOC. Using the get command you can pull any available input. With no parameters the input for today will be pulled.
$ bb aoc get --year <YEAR> --day <DAY>
If the input has already been pulled, the command will not re-pull the input. If the puzzle isn't unlocked yet, or your session has expired, the command prints a message saying so and exits non-zero.
A clojure.test runner has also been included if you want to write tests against your solution. This can be a helpful way to use the samples which are provided in the puzzles each day.
All tests in the solution's namespace will be executed. The command exits with a non-zero status if any test fails. To run your tests use the test command.
$ bb aoc test --year <YEAR> --day <DAY>
When you are ready to run your solution, the framework is ready to help with the solve command. This command will check for input and automatically download if missing. The input will be passed to the generator fn within your ns. The result of the generator will be passed to both the solve-part-1 and solve-part-2 functions. The result of both functions will be printed along with how long each took. Lazy results are realised inside the timing, so a lazy generator's parsing time is reported against the generator rather than part 1. Anything your functions print (e.g. debug output) is shown as normal. If no parameters are passed today's date will be used.
$ bb aoc solve --year <YEAR> --day <DAY>
If your solutions need any additional dependencies you can add them to the :deps map within the bb.edn. They will be pulled automatically on the next run.
Currently all solutions will run within GraalVM and more specifically the babashka runtime environment. Not all features of clojure are supported. There are a number of libraries pre-included with babashka that you can make use of with no additional configuration. See the docs for more information.
To change the generated solution files, put a solution.template file in the root of your repo. __YEAR__ and __DAY__ are replaced with the puzzle's year and day. The default template is resources/solution.template, which is a good starting point.
Run the library's tests with bb test.
init command sets up a project (bb.edn, .gitignore, src/) in one stepaoc task in bb.edn runs every command (bb aoc solve, bb aoc help, ...), so new commands no longer need bb.edn changes. The per-command task functions still workbb aoc new or bb new):user-agent in auth.ednbb auth :help prints help instead of a missing-argument errorbb get and bb test exit non-zero on failurepr-str (so nil rather than null)auth.edn is created readable by the owner onlysolution.template filedeps.edn, so the library can also be used as a git or local dependencybench task using criterium to benchmark solution time.tools-version file to help choose a compatible jvmCan you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |