Solve Advent of Code interactively, without leaving your IDE, with Kotlin Notebook!
aocKotlinNotebook.mp4
To use Kotlin Notebook you need to have IntelliJ IDEA Ultimate (paid version).
You can start a trial for 30 days, or use Early Access version for free (not always available).
Install Kotlin Notebook Plugin.
Just type this inside of the Kotlin Notebook:
@file:DependsOn("com.toldoven.aoc:aoc-kotlin-notebook:1.1.2")
Or with Gradle inside of build.gradle.kts
if you don't want to add it manually every time you create a new notebook:
dependencies {
implementation("com.toldoven.aoc:aoc-kotlin-notebook:1.1.2")
}
Don't forget to restart the Notebook kernel after adding a new dependency with Gradle.
Open the developer console on the Advent of Code website and grab the session
cookie.
Open Kotlin Notebook settings and set the environment variable AOC_TOKEN
.
When constructing a client use AocClient.fromEnv()
.
Create a file in the current working directory called .aocToken
and paste your token inside.
When constructing a client use AocClient.fromFile()
.
You can specify a different path to the file with the AOC_TOKEN_FILE
environment variable.
If you're uploading your solutions to GitHub — don't forget to add files with your token and cache to .gitignore
.
Caution
If you're using Kotlin Notebook environment variables, they are not ignored by default.
They are saved in the .idea/kotlinNotebook.xml
file.
All data that doesn't change is cached. This includes puzzle descriptions, input, and solutions.
The default cache folder is .aocCache
in the current working directory. You can change it with AOC_CACHE_DIR
environment variable.
Warning
Add cache folder to .gitignore
.
Redistributing Advent of Code puzzle descriptions and inputs is NOT ALLOWED.
Since input and solutions are unique for each user, they are stored in a folder named with a secure hashed session token.
Check out the example: example.ipynb
// Initialize a day
val aoc = AocClient.fromEnv().interactiveDay(2019, 1)
// Interactive timer synchronized with server time
aoc.waitUntilUnlocked()
// View part one problem description
aoc.viewPartOne()
// Get the input
aoc.input()
// Submit the first part
aoc.submitPartOne(123)
// View part two problem description
aoc.viewPartTwo()
// Submit the second part
aoc.submitPartOne("321")
Note
To display the value in the Notebook — it needs to be on the last line of the block, or you can use DISPLAY(...)
function.
This tool follows the automation guidelines on the /r/adventofcode community wiki.
- Everything that can be cached is cached. (Source)
- The calls to Advent of Code website are not throttled, because each call requires action from the user, and it's up to the user to use it responsibly.
- The User-Agent header contains a link to this repo and contact info. (Source)
A few ideas I will hopefully get to implement.
- A way to run tests.
- Perhaps a way to extract tests from the description automatically with an LLM. Not sure if this is legal, though.
- Improve integration using Kotlin Notebook's API.
- A way to receive a notification when you can submit again after failing.