AOC2024
Advent of Code 2024 solutions written in Kotlin, working through all December puzzles with clean, readable implementations.

Solutions to all of Advent of Code 2024's daily puzzles, written in Kotlin. Each day is solved independently with an emphasis on readable, idiomatic implementations rather than maximally golfed one-liners — the puzzles range from parsing and simulation to graph search and constraint solving, and the solutions double as a running log of which Kotlin standard-library idioms (sequences, destructuring, sealed classes for puzzle-specific state) fit which problem shape best.
Under the hood
Each day is a self-contained Kotlin file (src/DayN/mainN.kt) reading its own input — Day 1 parses two columns, sorts both, and sums absolute distances for part 1, then a similarity score for part 2.
fun main() {
val input = File("src/Day1/$fileName").readLines()
val left = mutableListOf<Int>()
val right = mutableListOf<Int>()
input.forEach {
left.add(it.split(" ")[0].toInt())
right.add(it.split(" ")[1].toInt())
}
left.sort()
right.sort()
val distances = mutableListOf<Int>()
left.forEachIndexed { index, s ->
distances.add(abs(right[index] - s))
}
println("Sum: ${distances.sum()}")
val similarityScores = mutableListOf<Int>()
left.forEach { l ->
similarityScores.add(right.filter { it == l }.size * l)
}
println("Sum: ${similarityScores.sum()}")
}