- Notifications
You must be signed in to change notification settings - Fork138
The Advent of Code template project for Kotlin
License
kotlin-hands-on/advent-of-code-kotlin-template
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Advent of Code – an annual event in December since 2015.Every year since then, with the first day of December, a programming puzzles contest is published every day for twenty-five days.A set of Christmas-oriented challenges provides any input you have to use to answer using the language of your choice.We offer you a template prepared to use withKotlin language within this repository.
Join us as we solve the Advent of Code challenges live on stream!Follow along to see step-by-step solutions, participate in problem-solving, and learn new strategies to tackle the puzzles.Whether you're stuck on a particular problem or just looking to improve your Kotlin skills, our live streams are here to help.
Advent of Code Kotlin Template is a particular type of GitHub repository that lets you speed up the setup phase and start writing your AoC solutions immediately.
The general idea is straightforward – to create a new project based on this template, you need to log in to your GitHub account and use theUse this template green button.And remember –do not fork it!
After creating a new project based on this template in your account, a dedicated GitHub Actions workflow will start and clean up the code from redundant files.It will also personalize code to use your username and project name in namespaces and Gradle properties.How cool is that?
You can clone it within the IntelliJ IDEA whenever the@actions-user actor pushes the second commit to your repository.
Important
Right after opening the project in IntelliJ IDEA, verify if you use at leastJava 11 as Project SDK.To do that, visitProject Structure Settings (⌘ Cmd; on macOS orCtrlAltShiftS on Windows/Linux).
From now on, everything's in your hands!Join theAdvent of Code contest to solve theDay 01 as soon as it is published.
Copy theDay01.kt
solution file for the following days and increment the day number.
Note
Remember to join the Kotlin contest!
To do that, edit your project'sAbout section with ⚙️ icon and add theaoc-2024-in-kotlin
topic to your project.
We will find your repository and count you in our giveaway.
After you create a new project based on the current template repository using theUse this template button, a bare minimal scaffold will appear in your GitHub account with the following structure:
.├── README.md README file├── build.gradle.kts Gradle configuration created with Kotlin DSL├── settings.gradle.kts Gradle project settings├── gradle* Gradle wrapper files└── src ├── Day01.kt An empty implementation for the first AoC day ├── Utils.kt A set of utility methods shared across your days │ │ (create those files manually) ├── Day01.txt An empty file for the Day 01 input data └── Day01_test.txt An optional Day 01 test input data used for checks
Note
All task input files (src/*.txt
) are excluded from the repository with.gitignore
– we should not post them publicly, asEric Wastl requested for.
When the first puzzle appears, go to theDay01.kt
, and for eachpart1
andpart2
function, provide an algorithm implementation using theinput
data loaded from thesrc/Day01.txt
file.This input data is common for both parts, and you can find it at the bottom of each day on theAdvent of Code page.
To read the input data, you can go with thereadInput(name: String)
utility method provided in theUtils.kt
file, like:
funmain() {funpart1(input:List<String>):Int {return input.size }val input= readInput("Day01")println(part1(input))}
To call the algorithm you're implementing, click the green Play button next to thefun main()
definition.
Important
Create relevant files Before running tasks or tests, like:src/Day01.txt
orsrc/Day01_test.txt
.
TheUtils.kt
file also contains theString.md5()
method for generating MD5 hash out of the given string and expects more helper functions for the sake of theKISS principle.
Each puzzle describes some test conditions, a small portion of the information that helps check if the produced value for the given test input is valid.To handle that case, you can put such an input into a separate file and perform a check against the output, like:
funmain() {// ...val testInput= readInput("Day01_test") check(part1(testInput)==13)}
The current approach of providing bothpart1
andpart2
solutions within the singleDay##.kt
file may sometimes bring a disadvantage due to the first solution calculation when we expect to work on the second part only.With simple cases that don't consume too much of your time and resources that can be almost unnoticeable, but when the solution takes seconds, it is worth considering breaking the daily solution into two separated pieces, likeDay07_part1.kt
andDay07_part2.kt
.
The final result of your algorithm will be printed on the screen so that you can pass it to the Advent of Code website.
To go with the next day, place theDay02.txt
file into thesrc
with relevant input data and create aDay02.kt
file with a similar code scaffold:
funmain() {funpart1(input:List<String>):Int {return0 }funpart2(input:List<String>):Int {return0 }val input= readInput("Day02")println(part1(input))println(part2(input))}
Note
There is a fork of this repository available that utilizes the Amper tool for project configuration, recentlyintroduced by JetBrains.
For more, seeAdvent of Code Kotlin Template — Amper project.
If you are stuck with Kotlin-specific questions or anything related to this template, check out the following resources:
About
The Advent of Code template project for Kotlin
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
Contributors10
Uh oh!
There was an error while loading.Please reload this page.