A template which will help you concentrate on the puzzle solutions. It brings
- Downloading and caching of the puzzle input
- A place to enter your puzzle solving code. Results are printed and the time gets measured.
- Tests to check your puzzle solving code against the example data you get each day.
- Click 'Use this template'
- Clone your new repository
- Open the project with IntelliJ Idea CE (recommended)
The setup process differs depending on how you are planning to execute your solutions.
- Via gradle from the command line
- Via the run button in IntelliJ
Either way, you will have to determine your session cookie beforehand.
The downloader tries to download the input for the current year. If you want to use this template for older puzzles you have to adjust it accordingly.
- Open adventofcode.com in your browser
- Login
- Open the developer tools
- Open the storage tab
- Select "Cookies" → "https://adventofcode.com"
- A table will open, the row with the name "session" is the correct one, the session cookie is the string in the "Value" field
- Setup (only needed once)
- Create the file
./gradle.properties
- Insert the line
sessionCookie=yourSessionCookieWithoutQuotes
- Create the file
- Execution for a day
- Execute
./gradlew run -Dday={day number}
- Execute
Alternatively you could skip the setup and pass the cookie as a parameter:
./gradlew run -Dday={day number} -DsessionCookie={session cookie}"
- Open one of the
Day{XY}.kt
files - Click the play button next to the
main
function, selectModify run configuration
- Insert your session cookie into the field
Program arguments
- Execute the day by clicking the run button again and select
Run
You have to repeat this for each day. Or you edit your run configuration each day to execute a different main function.
Tests are prepared. They are written with KoTest.
Please make sure to install the KoTest IntelliJ Idea plugin from the plugin repository in the settings.
Each day you can insert the given example data and solution into the according test class. Running the tests will check if your solution will result in the correct answer.
You can execute the tests with one of these options:
- Click the play button next to the test class or method (KoTest plugin required)
- Select and run the according run configuration
- Execute
./gradlew :app:test --tests "day{XY}.Day{XY}Test"
If you want to write more tests along the way:
- For KoTests API have a look into the documentation and the list of assertions.
- If you need to mock something, MockK is ready to go.