Advent of Code 2026 - Day 1, in Kotlin - Dusty Shed
Kotlin solutions to parts 1 and 2 of Advent of Code 2026, Day 1: 'Dusty Shed'
December 1 means one thing, Advent of Code is back! This is my 10th year blogging solutions in Kotlin. I am not going to use AI in any way to complete the Advent of Code 2026 puzzles. I like the challenge of solving these by hand, as I have done in the past. Occasionally, I will get help from Reddit or the Kotlin slack if I run into a puzzle I can’t solve on my own.
If you’d rather just view the code, my GitHub Repository is here.
Puzzle Input
From year to year, I keep a set of functions to load the puzzle input from a file and turn it into some simple data structure, like a List<String>. They don’t do anything else and make the actual puzzle solution a bit cleaner. These are usually driven from unit tests.
Today, we’ll take input as a List<String>, map each String to an Int, and turn that into a Map<Int, Int> via groupingBy and eachCount. The key in the map is the container id, and the value is how many we saw in the input.
class Day01(input: List<String>) {
private val ids = input.map { it.toInt() }.groupingBy { it }.eachCount()
}
⭐ Day 1, Part 1
The puzzle text can be found here.
Because we got our input into a Map<Int, Int> before, Part 1 involves picking out the three components we care about and multiplying them. We look at all of the entries, order them descending by count (most first), take(3) to get the ones we care about, map each of the keys (the component IDs), and then multiply them together via reduce.
// In Day01
fun solvePart1(): Int =
ids.entries
.sortedByDescending{ it.value }
.take(3)
.map { it.key }
.reduce(Int::times)
Star earned! Onward!
⭐ Day 1, Part 2
The puzzle text can be found here.
The solution to Part 2 is the same as Part 1 except we sort the entries ascending (lowest to hightest).
// In Day01
fun solvePart1(): Int =
ids.entries
.sortedBy{ it.value }
.take(3)
.map { it.key }
.reduce(Int::times)
Star earned! See you tomorrow!
Further Reading
- Index of All Solutions - All posts and solutions for 2026, in Kotlin.
- My Github repo - Solutions and tests for each day.
- Solution - Full code for day 1
- Advent of Code - Come join in and do these challenges yourself!