17

Day 11: Reactor

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

you are viewing a single comment's thread
view the rest of the comments
[-] eco_game@discuss.tchncs.de 2 points 5 days ago

Kotlin

Part 1 was very straightforward, just a simple, cached recursive crawler.

In hindsight, part 2 works great with the same code and a small restriction. This took me quite a few off-by-one errors and Integer overflows to properly code though.

Solution

class Day11 : Puzzle {

    val links = mutableMapOf<String, List<String>>()
    val input1 = "you"
    val input2 = "svr"
    val output = "out"

    val cache = mutableMapOf<Pair<String, Set<Pair<String, Boolean>>>, Long>()

    override fun readFile() {
        val input = readInputFromFile(2025, 11, false)
        for (line in input.lines().filter { it.isNotBlank() }) {
            val split = line.split(": ")
            links[split[0]] = split[1].split(" ")
        }
    }

    override fun solvePartOne(): String {
        return travel(input1, setOf()).toString()
    }

    override fun solvePartTwo(): String {
        val passed = listOf("dac", "fft")
            .map { Pair(it, false) }
            .toSet()
        return travel(input2, passed).toString()
    }

    private fun travel(input: String, passed: Set<Pair<String, Boolean>>): Long {
        if (cache.containsKey(Pair(input, passed))) return cache[Pair(input, passed)]!!
        if (input == output) return if (passed.all { it.second }) 1L else 0L
        val newPassed = if (input in passed.map { it.first }) {
            passed.map { if (it.first == input) input to true else it }.toSet()
        } else {
            passed
        }
        val paths = links[input]!!
        val sum = paths.sumOf { travel(it, newPassed) }
        cache[Pair(input, newPassed)] = sum
        return sum
    }
}

full code on Codeberg

this post was submitted on 11 Dec 2025
17 points (100.0% liked)

Advent Of Code

1261 readers
2 users here now

An unofficial home for the advent of code community on programming.dev! Other challenges are also welcome!

Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.

Everybody Codes is another collection of programming puzzles with seasonal events.

EC 2025

AoC 2025

Solution Threads

M T W T F S S
1 2 3 4 5 6 7
8 9 10 11 12

Visualisations Megathread

Rules/Guidelines

Relevant Communities

Relevant Links

Credits

Icon base by Lorc under CC BY 3.0 with modifications to add a gradient

console.log('Hello World')

founded 3 years ago
MODERATORS